mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-18 22:30:00 +00:00
split NMS away from core bukkit code
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package com.dfsek.terra.bukkit;
|
||||
|
||||
import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class BukkitAddon implements BaseAddon {
|
||||
private static final Version VERSION = Versions.getVersion(1, 0, 0);
|
||||
|
||||
private final PlatformImpl terraBukkitPlugin;
|
||||
|
||||
public BukkitAddon(PlatformImpl terraBukkitPlugin) {
|
||||
this.terraBukkitPlugin = terraBukkitPlugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
terraBukkitPlugin.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigurationLoadEvent.class)
|
||||
.then(event -> {
|
||||
if(event.is(Biome.class)) {
|
||||
event.getLoadedObject(Biome.class).getContext().put(event.load(new VanillaBiomeProperties()));
|
||||
}
|
||||
})
|
||||
.global();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "terra-bukkit";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.api.command.CommandSender;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.Player;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
|
||||
|
||||
public class BukkitCommandSender implements CommandSender {
|
||||
private final org.bukkit.command.CommandSender delegate;
|
||||
|
||||
public BukkitCommandSender(org.bukkit.command.CommandSender delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
delegate.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Entity> getEntity() {
|
||||
if(delegate instanceof org.bukkit.entity.Entity entity) {
|
||||
return Optional.of(BukkitAdapter.adapt(entity));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Player> getPlayer() {
|
||||
if(delegate instanceof org.bukkit.entity.Player player) {
|
||||
return Optional.of(BukkitAdapter.adapt(player));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.command.CommandSender getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
|
||||
|
||||
public class BukkitEntity implements Entity {
|
||||
private final org.bukkit.entity.Entity entity;
|
||||
|
||||
public BukkitEntity(org.bukkit.entity.Entity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getHandle() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 position() {
|
||||
return BukkitAdapter.adapt(entity.getLocation().toVector());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void position(Vector3 location) {
|
||||
entity.teleport(BukkitAdapter.adapt(location).toLocation(entity.getWorld()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void world(ServerWorld world) {
|
||||
Location newLoc = entity.getLocation().clone();
|
||||
newLoc.setWorld(BukkitAdapter.adapt(world));
|
||||
entity.teleport(newLoc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerWorld world() {
|
||||
return BukkitAdapter.adapt(entity.getWorld());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import com.dfsek.terra.api.entity.Player;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
|
||||
|
||||
public class BukkitPlayer implements Player {
|
||||
private final org.bukkit.entity.Player delegate;
|
||||
|
||||
public BukkitPlayer(org.bukkit.entity.Player delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Player getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 position() {
|
||||
org.bukkit.Location bukkit = delegate.getLocation();
|
||||
return Vector3.of(bukkit.getX(), bukkit.getY(), bukkit.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void position(Vector3 location) {
|
||||
delegate.teleport(BukkitAdapter.adapt(location).toLocation(delegate.getWorld()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void world(ServerWorld world) {
|
||||
Location newLoc = delegate.getLocation().clone();
|
||||
newLoc.setWorld(BukkitAdapter.adapt(world));
|
||||
delegate.teleport(newLoc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerWorld world() {
|
||||
return BukkitAdapter.adapt(delegate.getWorld());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit;
|
||||
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.bukkit.handles.BukkitItemHandle;
|
||||
import com.dfsek.terra.bukkit.handles.BukkitWorldHandle;
|
||||
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
|
||||
|
||||
|
||||
public class PlatformImpl extends AbstractPlatform {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PlatformImpl.class);
|
||||
|
||||
private final ItemHandle itemHandle = new BukkitItemHandle();
|
||||
|
||||
private final WorldHandle handle = new BukkitWorldHandle();
|
||||
|
||||
private final TerraBukkitPlugin plugin;
|
||||
|
||||
public PlatformImpl(TerraBukkitPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
load();
|
||||
}
|
||||
|
||||
public TerraBukkitPlugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reload() {
|
||||
getTerraConfig().load(this);
|
||||
getRawConfigRegistry().clear();
|
||||
boolean succeed = getRawConfigRegistry().loadAll(this);
|
||||
|
||||
Bukkit.getWorlds().forEach(world -> {
|
||||
if(world.getGenerator() instanceof BukkitChunkGeneratorWrapper wrapper) {
|
||||
getConfigRegistry().get(wrapper.getPack().getRegistryKey()).ifPresent(pack -> {
|
||||
wrapper.setPack(pack);
|
||||
LOGGER.info("Replaced pack in chunk generator for world {}", world);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return succeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String platformName() {
|
||||
return "Bukkit";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runPossiblyUnsafeTask(@NotNull Runnable task) {
|
||||
Bukkit.getScheduler().runTask(plugin, task);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<BaseAddon> platformAddon() {
|
||||
return List.of(new BukkitAddon(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull WorldHandle getWorldHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull File getDataFolder() {
|
||||
return plugin.getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemHandle getItemHandle() {
|
||||
return itemHandle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
super.register(registry);
|
||||
registry.registerLoader(BlockState.class, (type, o, loader, depthTracker) -> handle.createBlockState((String) o))
|
||||
.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
|
||||
.registerLoader(EntityType.class, (type, o, loader, depthTracker) -> EntityType.valueOf((String) o));
|
||||
|
||||
}
|
||||
|
||||
private BukkitPlatformBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
|
||||
if(!id.startsWith("minecraft:")) throw new LoadException("Invalid biome identifier " + id, depthTracker);
|
||||
return new BukkitPlatformBiome(org.bukkit.block.Biome.valueOf(id.toUpperCase(Locale.ROOT).substring(10)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit;
|
||||
|
||||
import cloud.commandframework.brigadier.CloudBrigadierManager;
|
||||
import cloud.commandframework.bukkit.CloudBukkitCapabilities;
|
||||
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||
import cloud.commandframework.paper.PaperCommandManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.command.CommandSender;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.bukkit.listeners.CommonListener;
|
||||
import com.dfsek.terra.bukkit.nms.Initializer;
|
||||
import com.dfsek.terra.bukkit.util.PaperUtil;
|
||||
import com.dfsek.terra.bukkit.util.VersionUtil;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
|
||||
|
||||
public class TerraBukkitPlugin extends JavaPlugin {
|
||||
private static final Logger logger = LoggerFactory.getLogger(TerraBukkitPlugin.class);
|
||||
|
||||
private final PlatformImpl platform = new PlatformImpl(this);
|
||||
private final Map<String, com.dfsek.terra.api.world.chunk.generation.ChunkGenerator> generatorMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if(!doVersionCheck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
platform.getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
|
||||
|
||||
try {
|
||||
PaperCommandManager<CommandSender> commandManager = new PaperCommandManager<>(this,
|
||||
CommandExecutionCoordinator.simpleCoordinator(),
|
||||
BukkitAdapter::adapt,
|
||||
BukkitAdapter::adapt);
|
||||
if(commandManager.queryCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) {
|
||||
commandManager.registerBrigadier();
|
||||
final CloudBrigadierManager<?, ?> brigManager = commandManager.brigadierManager();
|
||||
if(brigManager != null) {
|
||||
brigManager.setNativeNumberSuggestions(false);
|
||||
}
|
||||
}
|
||||
|
||||
if(commandManager.queryCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) {
|
||||
commandManager.registerAsynchronousCompletions();
|
||||
}
|
||||
|
||||
platform.getEventManager().callEvent(new CommandRegistrationEvent(commandManager));
|
||||
|
||||
} catch(Exception e) { // This should never happen.
|
||||
logger.error("""
|
||||
TERRA HAS BEEN DISABLED
|
||||
|
||||
Errors occurred while registering commands.
|
||||
Please report this to Terra.
|
||||
""".strip(), e);
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new CommonListener(), this); // Register master event listener
|
||||
PaperUtil.checkPaper(this);
|
||||
|
||||
Initializer.init(platform);
|
||||
}
|
||||
|
||||
public PlatformImpl getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "deprecation", "AccessOfSystemProperties" })
|
||||
private boolean doVersionCheck() {
|
||||
logger.info("Running on Minecraft version {} with server implementation {}.", VersionUtil.getMinecraftVersionInfo(),
|
||||
Bukkit.getServer().getName());
|
||||
|
||||
if(!VersionUtil.getSpigotVersionInfo().isSpigot())
|
||||
logger.error("YOU ARE RUNNING A CRAFTBUKKIT OR BUKKIT SERVER. PLEASE UPGRADE TO PAPER.");
|
||||
|
||||
if(VersionUtil.getSpigotVersionInfo().isMohist()) {
|
||||
if(System.getProperty("IKnowMohistCausesLotsOfIssuesButIWillUseItAnyways") == null) {
|
||||
Runnable runnable = () -> { // scary big block of text
|
||||
logger.error("""
|
||||
.----------------------------------------------------------------------------------.
|
||||
| |
|
||||
| ⚠ !! Warning !! ⚠ |
|
||||
| |
|
||||
| You are currently using Mohist. |
|
||||
| |
|
||||
| Do not use Mohist. |
|
||||
| |
|
||||
| The concept of combining the rigid Bukkit platform, which assumes a 100% |
|
||||
| Vanilla server, with the flexible Forge platform, which allows changing |
|
||||
| core components of the game, simply does not work. These platforms are |
|
||||
| incompatible at a conceptual level, the only way to combine them would |
|
||||
| be to make incompatible changes to both. As a result, Mohist's Bukkit |
|
||||
| API implementation is not compliant. This will cause many plugins to |
|
||||
| break. Rather than fix their platform, Mohist has chosen to distribute |
|
||||
| unofficial builds of plugins they deem to be "fixed". These builds are not |
|
||||
| "fixed", they are simply hacked together to work with Mohist's half-baked |
|
||||
| Bukkit implementation. To distribute these as "fixed" versions implies that: |
|
||||
| - These builds are endorsed by the original developers. (They are not) |
|
||||
| - The issue is on the plugin's end, not Mohist's. (It is not. The issue |
|
||||
| is that Mohist chooses to not create a compliant Bukkit implementation) |
|
||||
| Please, do not use Mohist. It causes issues with most plugins, and rather |
|
||||
| than fixing their platform, Mohist has chosen to distribute unofficial |
|
||||
| hacked-together builds of plugins, calling them "fixed". If you want |
|
||||
| to use a server API with Forge mods, look at the Sponge project, an |
|
||||
| API that is designed to be implementation-agnostic, with first-party |
|
||||
| support for the Forge mod loader. You are bound to encounter issues if |
|
||||
| you use Terra with Mohist. We will provide NO SUPPORT for servers running |
|
||||
| Mohist. If you wish to proceed anyways, you can add the JVM System Property |
|
||||
| "IKnowMohistCausesLotsOfIssuesButIWillUseItAnyways" to enable the plugin. No |
|
||||
| support will be provided for servers running Mohist. |
|
||||
| |
|
||||
| Because of this **TERRA HAS BEEN DISABLED**. |
|
||||
| Do not come ask us why it is not working. |
|
||||
| |
|
||||
|----------------------------------------------------------------------------------|
|
||||
""".strip());
|
||||
};
|
||||
runnable.run();
|
||||
Bukkit.getScheduler().scheduleAsyncDelayedTask(this, runnable, 200L);
|
||||
// Bukkit.shutdown(); // we're not *that* evil
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return false;
|
||||
} else {
|
||||
logger.warn("""
|
||||
You are using Mohist, so we will not give you any support for issues that may arise.
|
||||
Since you enabled the "IKnowMohistCausesLotsOfIssuesButIWillUseItAnyways" flag, we won't disable Terra. But be warned.
|
||||
|
||||
> I felt a great disturbance in the JVM, as if millions of plugins suddenly cried out in stack traces and were suddenly silenced.
|
||||
> I fear something terrible has happened.
|
||||
> - Astrash
|
||||
""".strip());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable
|
||||
ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, String id) {
|
||||
return new BukkitChunkGeneratorWrapper(generatorMap.computeIfAbsent(worldName, name -> {
|
||||
ConfigPack pack = platform.getConfigRegistry().getByID(id).orElseThrow(
|
||||
() -> new IllegalArgumentException("No such config pack \"" + id + "\""));
|
||||
return pack.getGeneratorProvider().newInstance(pack);
|
||||
}), platform.getRawConfigRegistry().getByID(id).orElseThrow(), platform.getWorldHandle().air());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.dfsek.terra.bukkit.config;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
|
||||
public class VanillaBiomeProperties implements ConfigTemplate, Properties {
|
||||
@Value("colors.grass")
|
||||
@Default
|
||||
private Integer grassColor = null;
|
||||
|
||||
@Value("colors.fog")
|
||||
@Default
|
||||
private Integer fogColor = null;
|
||||
|
||||
@Value("colors.water")
|
||||
@Default
|
||||
private Integer waterColor = null;
|
||||
|
||||
@Value("colors.water-fog")
|
||||
@Default
|
||||
private Integer waterFogColor = null;
|
||||
|
||||
@Value("colors.foliage")
|
||||
@Default
|
||||
private Integer foliageColor = null;
|
||||
|
||||
@Value("colors.sky")
|
||||
@Default
|
||||
private Integer skyColor = null;
|
||||
|
||||
public Integer getFogColor() {
|
||||
return fogColor;
|
||||
}
|
||||
|
||||
public Integer getFoliageColor() {
|
||||
return foliageColor;
|
||||
}
|
||||
|
||||
public Integer getGrassColor() {
|
||||
return grassColor;
|
||||
}
|
||||
|
||||
public Integer getWaterColor() {
|
||||
return waterColor;
|
||||
}
|
||||
|
||||
public Integer getWaterFogColor() {
|
||||
return waterFogColor;
|
||||
}
|
||||
|
||||
public Integer getSkyColor() {
|
||||
return skyColor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.dfsek.terra.bukkit.generator;
|
||||
|
||||
import org.bukkit.generator.BiomeProvider;
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
|
||||
public class BukkitBiomeProvider extends BiomeProvider implements Handle {
|
||||
private final com.dfsek.terra.api.world.biome.generation.BiomeProvider delegate;
|
||||
|
||||
public BukkitBiomeProvider(com.dfsek.terra.api.world.biome.generation.BiomeProvider delegate) { this.delegate = delegate; }
|
||||
|
||||
@Override
|
||||
public @NotNull org.bukkit.block.Biome getBiome(@NotNull WorldInfo worldInfo, int x, int y, int z) {
|
||||
Biome biome = delegate.getBiome(x, y, z, worldInfo.getSeed());
|
||||
return (org.bukkit.block.Biome) biome.getPlatformBiome().getHandle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<org.bukkit.block.Biome> getBiomes(@NotNull WorldInfo worldInfo) {
|
||||
return StreamSupport.stream(delegate.getBiomes().spliterator(), false)
|
||||
.map(terraBiome -> (org.bukkit.block.Biome) terraBiome.getPlatformBiome().getHandle())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.generator;
|
||||
|
||||
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.generator.BiomeProvider;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.LimitedRegion;
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
|
||||
import com.dfsek.terra.bukkit.world.BukkitProtoWorld;
|
||||
import com.dfsek.terra.bukkit.world.BukkitWorldProperties;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGenerator implements GeneratorWrapper {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BukkitChunkGeneratorWrapper.class);
|
||||
private final BlockState air;
|
||||
private ChunkGenerator delegate;
|
||||
private ConfigPack pack;
|
||||
|
||||
public BukkitChunkGeneratorWrapper(ChunkGenerator delegate, ConfigPack pack, BlockState air) {
|
||||
this.delegate = delegate;
|
||||
this.pack = pack;
|
||||
this.air = air;
|
||||
}
|
||||
|
||||
public void setDelegate(ChunkGenerator delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BiomeProvider getDefaultBiomeProvider(@NotNull WorldInfo worldInfo) {
|
||||
return new BukkitBiomeProvider(pack.getBiomeProvider());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateNoise(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z, @NotNull ChunkData chunkData) {
|
||||
BukkitWorldProperties properties = new BukkitWorldProperties(worldInfo);
|
||||
delegate.generateChunkData(new BukkitProtoChunk(chunkData), properties, pack.getBiomeProvider().caching(properties), x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
||||
return pack.getStages()
|
||||
.stream()
|
||||
.map(generationStage -> new BlockPopulator() {
|
||||
@Override
|
||||
public void populate(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z,
|
||||
@NotNull LimitedRegion limitedRegion) {
|
||||
generationStage.populate(new BukkitProtoWorld(limitedRegion, air));
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateCaves() {
|
||||
return false;
|
||||
//return pack.vanillaCaves();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateDecorations() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateMobs() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateStructures() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public void setPack(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
setDelegate(pack.getGeneratorProvider().newInstance(pack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.generator;
|
||||
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;
|
||||
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
|
||||
|
||||
|
||||
public class BukkitProtoChunk implements ProtoChunk {
|
||||
|
||||
private final ChunkGenerator.ChunkData delegate;
|
||||
|
||||
public BukkitProtoChunk(ChunkGenerator.ChunkData delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator.ChunkData getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return delegate.getMaxHeight();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, @NotNull BlockState blockState) {
|
||||
delegate.setBlock(x, y, z, ((BukkitBlockState) blockState).getHandle());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public @NotNull BlockState getBlock(int x, int y, int z) {
|
||||
return BukkitBlockState.newInstance(delegate.getBlockData(x, y, z));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.handles;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.inventory.Item;
|
||||
import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.bukkit.util.MinecraftUtils;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
|
||||
|
||||
public class BukkitItemHandle implements ItemHandle {
|
||||
|
||||
@Override
|
||||
public Item createItem(String data) {
|
||||
return BukkitAdapter.adapt(Material.matchMaterial(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enchantment getEnchantment(String id) {
|
||||
return BukkitAdapter.adapt(
|
||||
org.bukkit.enchantments.Enchantment.getByKey(NamespacedKey.minecraft(MinecraftUtils.stripMinecraftNamespace(id))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Enchantment> getEnchantments() {
|
||||
return Arrays.stream(org.bukkit.enchantments.Enchantment.values()).map(BukkitAdapter::adapt).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.handles;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
|
||||
import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
|
||||
|
||||
|
||||
public class BukkitWorldHandle implements WorldHandle {
|
||||
private final BlockState air;
|
||||
|
||||
public BukkitWorldHandle() {
|
||||
this.air = BukkitBlockState.newInstance(Material.AIR.createBlockData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized @NotNull BlockState createBlockState(@NotNull String data) {
|
||||
org.bukkit.block.data.BlockData bukkitData = Bukkit.createBlockData(
|
||||
data); // somehow bukkit managed to make this not thread safe! :)
|
||||
return BukkitBlockState.newInstance(bukkitData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BlockState air() {
|
||||
return air;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull EntityType getEntity(@NotNull String id) {
|
||||
if(!id.startsWith("minecraft:")) throw new IllegalArgumentException("Invalid entity identifier " + id);
|
||||
return new BukkitEntityType(org.bukkit.entity.EntityType.valueOf(id.toUpperCase(Locale.ROOT).substring(10)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.listeners;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
|
||||
/**
|
||||
* Listener for events on all implementations.
|
||||
*/
|
||||
public class CommonListener implements Listener {
|
||||
public CommonListener() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.listeners;
|
||||
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
|
||||
import org.bukkit.event.entity.VillagerCareerChangeEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
|
||||
/**
|
||||
* Listener to load on Spigot servers, contains Villager crash prevention and hacky ender eye redirection.
|
||||
* <p>
|
||||
* (This is currently loaded on all servers; once Paper accepts the StructureLocateEvent PR this will only be loaded on servers without
|
||||
* StructureLocateEvent).
|
||||
*/
|
||||
public class SpigotListener implements Listener {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SpigotListener.class);
|
||||
private final Platform platform;
|
||||
|
||||
public SpigotListener(Platform platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onEnderEye(EntitySpawnEvent e) {
|
||||
/*
|
||||
Entity entity = e.getEntity();
|
||||
if(e.getEntityType() == EntityType.ENDER_SIGNAL) {
|
||||
logger.info("Detected Ender Signal...");
|
||||
World w = BukkitAdapter.adapt(e.getEntity().getWorld());
|
||||
EnderSignal signal = (EnderSignal) entity;
|
||||
ConfiguredStructure config = tw.getConfig().getRegistry(TerraStructure.class).get(w.getConfig().getLocatable().get
|
||||
("STRONGHOLD"));
|
||||
if(config != null) {
|
||||
logger.info("Overriding Ender Signal...");
|
||||
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getLocation()
|
||||
.toVector()), tw.getWorld(), 0, 500, location -> {
|
||||
if(location != null)
|
||||
signal.setTargetLocation(BukkitAdapter.adapt(location).toLocation(e.getLocation().getWorld()));
|
||||
logger.info("Location: {}", location);
|
||||
}, main);
|
||||
finder.run(); // Do this synchronously so eye doesn't change direction several ticks after spawning.
|
||||
} else
|
||||
logger.warn("No overrides are defined for Strongholds. Ender Signals will not work correctly.");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCartographerChange(VillagerAcquireTradeEvent e) {
|
||||
if(!(e.getEntity() instanceof Villager))
|
||||
return;
|
||||
if(((Villager) e.getEntity()).getProfession() == Villager.Profession.CARTOGRAPHER) {
|
||||
logger.error("""
|
||||
.------------------------------------------------------------------------.
|
||||
| Prevented server crash by stopping Cartographer villager from |
|
||||
| spawning. Please upgrade to Paper, which has a StructureLocateEvent |
|
||||
| that fixes this issue at the source, and doesn't require us to do |
|
||||
| stupid band-aids. |
|
||||
|------------------------------------------------------------------------|
|
||||
""".strip());
|
||||
e.setCancelled(true); // Cancel leveling if the villager is a Cartographer, to prevent crashing server.
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCartographerLevel(VillagerCareerChangeEvent e) {
|
||||
if(e.getProfession() == Villager.Profession.CARTOGRAPHER) {
|
||||
logger.error("""
|
||||
.------------------------------------------------------------------------.
|
||||
| Prevented server crash by stopping Cartographer villager from leveling |
|
||||
| up. Please upgrade to Paper, which has a StructureLocateEvent that |
|
||||
| fixes this issue at the source, and doesn't require us to do stupid |
|
||||
| band-aids. |
|
||||
|------------------------------------------------------------------------|
|
||||
""".strip());
|
||||
e.getEntity().setProfession(Villager.Profession.NITWIT); // Give villager new profession to prevent server crash.
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import com.dfsek.terra.bukkit.PlatformImpl;
|
||||
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
|
||||
public interface Initializer {
|
||||
String NMS = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
String TERRA_PACKAGE = Initializer.class.getPackageName();
|
||||
|
||||
void initialize(PlatformImpl plugin);
|
||||
|
||||
static void init(PlatformImpl platform) {
|
||||
Logger logger = LoggerFactory.getLogger(Initializer.class);
|
||||
try {
|
||||
Class<?> initializerClass = Class.forName(TERRA_PACKAGE + "." + NMS + ".NMSInitializer");
|
||||
try {
|
||||
Initializer initializer = (Initializer) initializerClass.getConstructor().newInstance();
|
||||
initializer.initialize(platform);
|
||||
} catch(ReflectiveOperationException e) {
|
||||
throw new RuntimeException("Error initializing NMS bindings. Report this to Terra.", e);
|
||||
}
|
||||
} catch(ClassNotFoundException e) {
|
||||
logger.warn("NMS bindings for version {} do not exist. Support for this version is limited.", NMS);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.util;
|
||||
|
||||
public final class MinecraftUtils {
|
||||
public static String stripMinecraftNamespace(String in) {
|
||||
if(in.startsWith("minecraft:")) return in.substring("minecraft:".length());
|
||||
return in;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.util;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import static io.papermc.lib.PaperLib.suggestPaper;
|
||||
|
||||
|
||||
public final class PaperUtil {
|
||||
public static void checkPaper(JavaPlugin main) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(main, () -> {
|
||||
if(!PaperLib.isPaper()) {
|
||||
suggestPaper(main);
|
||||
}
|
||||
}, 100L);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.dfsek.terra.bukkit.util;
|
||||
|
||||
import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public final class VersionUtil {
|
||||
public static final SpigotVersionInfo SPIGOT_VERSION_INFO;
|
||||
public static final MinecraftVersionInfo MINECRAFT_VERSION_INFO;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(VersionUtil.class);
|
||||
|
||||
static {
|
||||
SPIGOT_VERSION_INFO = new SpigotVersionInfo();
|
||||
|
||||
MinecraftVersionInfo mcVersionInfo;
|
||||
try {
|
||||
mcVersionInfo = new MinecraftVersionInfo();
|
||||
} catch(Throwable t) {
|
||||
logger.error("Error while parsing minecraft version info. Continuing launch, but setting all versions to -1.");
|
||||
mcVersionInfo = new MinecraftVersionInfo(-1, -1, -1);
|
||||
}
|
||||
MINECRAFT_VERSION_INFO = mcVersionInfo;
|
||||
}
|
||||
|
||||
public static MinecraftVersionInfo getMinecraftVersionInfo() {
|
||||
return MINECRAFT_VERSION_INFO;
|
||||
}
|
||||
|
||||
public static SpigotVersionInfo getSpigotVersionInfo() {
|
||||
return SPIGOT_VERSION_INFO;
|
||||
}
|
||||
|
||||
public static final class SpigotVersionInfo {
|
||||
private final boolean spigot;
|
||||
private final boolean paper;
|
||||
private final boolean mohist;
|
||||
|
||||
|
||||
public SpigotVersionInfo() {
|
||||
logger.debug("Parsing spigot version info...");
|
||||
|
||||
paper = PaperLib.isPaper();
|
||||
spigot = PaperLib.isSpigot();
|
||||
|
||||
|
||||
boolean isMohist = false;
|
||||
try {
|
||||
Class.forName("com.mohistmc.MohistMC");
|
||||
// it's mohist
|
||||
isMohist = true;
|
||||
} catch(ClassNotFoundException ignore) { }
|
||||
this.mohist = isMohist;
|
||||
|
||||
logger.debug("Spigot version info parsed successfully.");
|
||||
}
|
||||
|
||||
public boolean isPaper() {
|
||||
return paper;
|
||||
}
|
||||
|
||||
public boolean isMohist() {
|
||||
return mohist;
|
||||
}
|
||||
|
||||
public boolean isSpigot() {
|
||||
return spigot;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final class MinecraftVersionInfo {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MinecraftVersionInfo.class);
|
||||
|
||||
private static final Pattern VERSION_PATTERN = Pattern.compile("v?(\\d+)_(\\d+)_R(\\d+)");
|
||||
private final int major;
|
||||
private final int minor;
|
||||
private final int patch;
|
||||
|
||||
private MinecraftVersionInfo() {
|
||||
this(Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]);
|
||||
}
|
||||
|
||||
private MinecraftVersionInfo(int major, int minor, int patch) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
}
|
||||
|
||||
private MinecraftVersionInfo(String versionString) {
|
||||
Matcher versionMatcher = VERSION_PATTERN.matcher(versionString);
|
||||
if(versionMatcher.find()) {
|
||||
major = Integer.parseInt(versionMatcher.group(1));
|
||||
minor = Integer.parseInt(versionMatcher.group(2));
|
||||
patch = Integer.parseInt(versionMatcher.group(3));
|
||||
} else {
|
||||
logger.warn("Error while parsing minecraft version info. Continuing launch, but setting all versions to -1.");
|
||||
|
||||
major = -1;
|
||||
minor = -1;
|
||||
patch = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(major == -1 && minor == -1 && patch == -1)
|
||||
return "Unknown";
|
||||
|
||||
return String.format("v%d.%d.%d", major, minor, patch);
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
return major;
|
||||
}
|
||||
|
||||
public int getMinor() {
|
||||
return minor;
|
||||
}
|
||||
|
||||
public int getPatch() {
|
||||
return patch;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world;
|
||||
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.properties.enums.Axis;
|
||||
import com.dfsek.terra.api.block.state.properties.enums.Half;
|
||||
import com.dfsek.terra.api.block.state.properties.enums.RailShape;
|
||||
import com.dfsek.terra.api.block.state.properties.enums.RedstoneConnection;
|
||||
import com.dfsek.terra.api.command.CommandSender;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
import com.dfsek.terra.bukkit.BukkitCommandSender;
|
||||
import com.dfsek.terra.bukkit.BukkitEntity;
|
||||
import com.dfsek.terra.bukkit.BukkitPlayer;
|
||||
import com.dfsek.terra.bukkit.world.block.BukkitBlockTypeAndItem;
|
||||
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
|
||||
import com.dfsek.terra.bukkit.world.inventory.BukkitItemStack;
|
||||
import com.dfsek.terra.bukkit.world.inventory.meta.BukkitEnchantment;
|
||||
import com.dfsek.terra.transform.MapTransform;
|
||||
import com.dfsek.terra.transform.TransformerImpl;
|
||||
|
||||
|
||||
/**
|
||||
* Utility class to adapt Bukkit enums to Terra enums.
|
||||
*/
|
||||
public final class BukkitAdapter {
|
||||
public static TransformerImpl<TreeType, String> TREE_TRANSFORMER = new TransformerImpl.Builder<TreeType, String>()
|
||||
.addTransform(new MapTransform<TreeType, String>()
|
||||
.add(TreeType.COCOA_TREE, "JUNGLE_COCOA")
|
||||
.add(TreeType.BIG_TREE, "LARGE_OAK")
|
||||
.add(TreeType.TALL_REDWOOD, "LARGE_SPRUCE")
|
||||
.add(TreeType.REDWOOD, "SPRUCE")
|
||||
.add(TreeType.TREE, "OAK")
|
||||
.add(TreeType.MEGA_REDWOOD, "MEGA_SPRUCE")
|
||||
.add(TreeType.SWAMP, "SWAMP_OAK"))
|
||||
.addTransform(TreeType::toString)
|
||||
.build();
|
||||
|
||||
|
||||
public static BlockState adapt(org.bukkit.block.data.BlockData data) {
|
||||
return BukkitBlockState.newInstance(data);
|
||||
}
|
||||
|
||||
public static org.bukkit.block.data.BlockData adapt(BlockState data) {
|
||||
return ((BukkitBlockState) data).getHandle();
|
||||
}
|
||||
|
||||
public static Axis adapt(org.bukkit.Axis axis) {
|
||||
return switch(axis) {
|
||||
case X -> Axis.X;
|
||||
case Y -> Axis.Y;
|
||||
case Z -> Axis.Z;
|
||||
};
|
||||
}
|
||||
|
||||
public static WorldProperties adapt(WorldInfo worldInfo) {
|
||||
return new BukkitWorldProperties(worldInfo);
|
||||
}
|
||||
|
||||
public static WorldInfo adapt(WorldProperties properties) {
|
||||
return (WorldInfo) properties.getHandle();
|
||||
}
|
||||
|
||||
public static Half adapt(org.bukkit.block.data.Bisected.Half half) {
|
||||
return switch(half) {
|
||||
case BOTTOM -> Half.BOTTOM;
|
||||
case TOP -> Half.TOP;
|
||||
};
|
||||
}
|
||||
|
||||
public static RedstoneConnection adapt(org.bukkit.block.data.type.RedstoneWire.Connection connection) {
|
||||
return switch(connection) {
|
||||
case NONE -> RedstoneConnection.NONE;
|
||||
case UP -> RedstoneConnection.UP;
|
||||
case SIDE -> RedstoneConnection.SIDE;
|
||||
};
|
||||
}
|
||||
|
||||
public static org.bukkit.block.data.type.RedstoneWire.Connection adapt(RedstoneConnection connection) {
|
||||
return switch(connection) {
|
||||
case SIDE -> org.bukkit.block.data.type.RedstoneWire.Connection.SIDE;
|
||||
case UP -> org.bukkit.block.data.type.RedstoneWire.Connection.UP;
|
||||
case NONE -> org.bukkit.block.data.type.RedstoneWire.Connection.NONE;
|
||||
};
|
||||
}
|
||||
|
||||
public static RailShape adapt(org.bukkit.block.data.Rail.Shape shape) {
|
||||
return switch(shape) {
|
||||
case SOUTH_WEST -> RailShape.SOUTH_WEST;
|
||||
case SOUTH_EAST -> RailShape.SOUTH_EAST;
|
||||
case NORTH_EAST -> RailShape.NORTH_EAST;
|
||||
case NORTH_WEST -> RailShape.NORTH_WEST;
|
||||
case ASCENDING_EAST -> RailShape.ASCENDING_EAST;
|
||||
case ASCENDING_WEST -> RailShape.ASCENDING_WEST;
|
||||
case ASCENDING_SOUTH -> RailShape.ASCENDING_SOUTH;
|
||||
case ASCENDING_NORTH -> RailShape.ASCENDING_NORTH;
|
||||
case NORTH_SOUTH -> RailShape.NORTH_SOUTH;
|
||||
case EAST_WEST -> RailShape.EAST_WEST;
|
||||
};
|
||||
}
|
||||
|
||||
public static org.bukkit.block.data.Rail.Shape adapt(RailShape shape) {
|
||||
return switch(shape) {
|
||||
case EAST_WEST -> org.bukkit.block.data.Rail.Shape.EAST_WEST;
|
||||
case NORTH_SOUTH -> org.bukkit.block.data.Rail.Shape.NORTH_SOUTH;
|
||||
case ASCENDING_NORTH -> org.bukkit.block.data.Rail.Shape.ASCENDING_NORTH;
|
||||
case ASCENDING_SOUTH -> org.bukkit.block.data.Rail.Shape.ASCENDING_SOUTH;
|
||||
case ASCENDING_WEST -> org.bukkit.block.data.Rail.Shape.ASCENDING_WEST;
|
||||
case ASCENDING_EAST -> org.bukkit.block.data.Rail.Shape.ASCENDING_EAST;
|
||||
case NORTH_WEST -> org.bukkit.block.data.Rail.Shape.NORTH_WEST;
|
||||
case NORTH_EAST -> org.bukkit.block.data.Rail.Shape.NORTH_EAST;
|
||||
case SOUTH_EAST -> org.bukkit.block.data.Rail.Shape.SOUTH_EAST;
|
||||
case SOUTH_WEST -> org.bukkit.block.data.Rail.Shape.SOUTH_WEST;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static org.bukkit.block.data.Bisected.Half adapt(Half half) {
|
||||
return switch(half) {
|
||||
case TOP -> org.bukkit.block.data.Bisected.Half.TOP;
|
||||
case BOTTOM -> org.bukkit.block.data.Bisected.Half.BOTTOM;
|
||||
default -> throw new IllegalStateException();
|
||||
};
|
||||
}
|
||||
|
||||
public static org.bukkit.Axis adapt(Axis axis) {
|
||||
return switch(axis) {
|
||||
case Z -> org.bukkit.Axis.Z;
|
||||
case Y -> org.bukkit.Axis.Y;
|
||||
case X -> org.bukkit.Axis.X;
|
||||
};
|
||||
}
|
||||
|
||||
public static Vector3 adapt(Location location) {
|
||||
return Vector3.of(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
public static Vector adapt(Vector3 vector3) {
|
||||
return new Vector(vector3.getX(), vector3.getY(), vector3.getZ());
|
||||
}
|
||||
|
||||
public static Vector3 adapt(Vector vector) {
|
||||
return Vector3.of(vector.getX(), vector.getY(), vector.getZ());
|
||||
}
|
||||
|
||||
public static CommandSender adapt(org.bukkit.command.CommandSender sender) {
|
||||
return new BukkitCommandSender(sender);
|
||||
}
|
||||
|
||||
public static Entity adapt(org.bukkit.entity.Entity entity) {
|
||||
return new BukkitEntity(entity);
|
||||
}
|
||||
|
||||
public static org.bukkit.command.CommandSender adapt(CommandSender sender) {
|
||||
return ((BukkitCommandSender) sender).getHandle();
|
||||
}
|
||||
|
||||
public static ServerWorld adapt(org.bukkit.World world) {
|
||||
return new BukkitServerWorld(world);
|
||||
}
|
||||
|
||||
public static org.bukkit.World adapt(ServerWorld world) {
|
||||
return (org.bukkit.World) world.getHandle();
|
||||
}
|
||||
|
||||
public static Chunk adapt(org.bukkit.Chunk chunk) {
|
||||
return new BukkitChunk(chunk);
|
||||
}
|
||||
|
||||
public static org.bukkit.Chunk adapt(Chunk chunk) {
|
||||
return (org.bukkit.Chunk) chunk.getHandle();
|
||||
}
|
||||
|
||||
public static Enchantment adapt(org.bukkit.enchantments.Enchantment enchantment) {
|
||||
return new BukkitEnchantment(enchantment);
|
||||
}
|
||||
|
||||
public static org.bukkit.enchantments.Enchantment adapt(Enchantment enchantment) {
|
||||
return ((BukkitEnchantment) enchantment).getHandle();
|
||||
}
|
||||
|
||||
public static Player adapt(com.dfsek.terra.api.entity.Player player) {
|
||||
return ((BukkitPlayer) player).getHandle();
|
||||
}
|
||||
|
||||
public static com.dfsek.terra.api.entity.Player adapt(Player player) {
|
||||
return new BukkitPlayer(player);
|
||||
}
|
||||
|
||||
public static BukkitBlockTypeAndItem adapt(Material material) {
|
||||
return new BukkitBlockTypeAndItem(material);
|
||||
}
|
||||
|
||||
public static Material adapt(BlockType type) {
|
||||
return ((BukkitBlockTypeAndItem) type).getHandle();
|
||||
}
|
||||
|
||||
public static ItemStack adapt(org.bukkit.inventory.ItemStack in) {
|
||||
return new BukkitItemStack(in);
|
||||
}
|
||||
|
||||
public static org.bukkit.inventory.ItemStack adapt(ItemStack in) {
|
||||
return ((BukkitItemStack) in).getHandle();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
|
||||
|
||||
public class BukkitChunk implements Chunk {
|
||||
private final org.bukkit.Chunk delegate;
|
||||
|
||||
public BukkitChunk(org.bukkit.Chunk delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.Chunk getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, BlockState data, boolean physics) {
|
||||
delegate.getBlock(x, y, z).setBlockData(BukkitAdapter.adapt(data), physics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, @NotNull BlockState blockState) {
|
||||
delegate.getBlock(x, y, z).setBlockData(BukkitAdapter.adapt(blockState));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BlockState getBlock(int x, int y, int z) {
|
||||
return BukkitAdapter.adapt(delegate.getBlock(x, y, z).getBlockData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return delegate.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return delegate.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerWorld getWorld() {
|
||||
return BukkitAdapter.adapt(delegate.getWorld());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world;
|
||||
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.properties.PropertyHolder;
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
|
||||
|
||||
public class BukkitPlatformBiome implements PlatformBiome, PropertyHolder {
|
||||
private final org.bukkit.block.Biome biome;
|
||||
private final Context context = new Context();
|
||||
|
||||
public BukkitPlatformBiome(org.bukkit.block.Biome biome) {
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.block.Biome getHandle() {
|
||||
return biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getContext() {
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.dfsek.terra.bukkit.world;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.generator.LimitedRegion;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
|
||||
import com.dfsek.terra.bukkit.BukkitEntity;
|
||||
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
|
||||
import com.dfsek.terra.bukkit.world.block.state.BukkitBlockEntity;
|
||||
import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
|
||||
|
||||
|
||||
public class BukkitProtoWorld implements ProtoWorld {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BukkitProtoWorld.class);
|
||||
private static final AtomicBoolean warn = new AtomicBoolean(true);
|
||||
private final LimitedRegion delegate;
|
||||
private final BlockState air;
|
||||
|
||||
public BukkitProtoWorld(LimitedRegion delegate, BlockState air) {
|
||||
this.delegate = delegate;
|
||||
this.air = air;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LimitedRegion getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
||||
access(x, y, z, () -> {
|
||||
delegate.setBlockData(x, y, z, BukkitAdapter.adapt(data));
|
||||
if(physics) {
|
||||
delegate.scheduleBlockUpdate(x, y, z);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return delegate.getWorld().getSeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return delegate.getWorld().getMaxHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(int x, int y, int z) {
|
||||
return access(x, y, z, () -> BukkitBlockState.newInstance(delegate.getBlockData(x, y, z))).orElse(air);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity getBlockEntity(int x, int y, int z) {
|
||||
return access(x, y, z, () -> BukkitBlockEntity.newInstance(delegate.getBlockState(x, y, z))).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return delegate.getWorld().getMinHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity spawnEntity(double x, double y, double z, EntityType entityType) {
|
||||
return access((int) x, (int) y, (int) z, () -> new BukkitEntity(
|
||||
delegate.spawnEntity(new Location(delegate.getWorld(), x, y, z), ((BukkitEntityType) entityType).getHandle()))).orElse(
|
||||
null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getGenerator() {
|
||||
return ((BukkitChunkGeneratorWrapper) delegate.getWorld().getGenerator()).getHandle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeProvider getBiomeProvider() {
|
||||
return ((BukkitChunkGeneratorWrapper) delegate.getWorld().getGenerator()).getPack().getBiomeProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return ((BukkitChunkGeneratorWrapper) delegate.getWorld().getGenerator()).getPack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int centerChunkX() {
|
||||
return delegate.getCenterChunkX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int centerChunkZ() {
|
||||
return delegate.getCenterChunkZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerWorld getWorld() {
|
||||
return new BukkitServerWorld(delegate.getWorld());
|
||||
}
|
||||
|
||||
private <T> Optional<T> access(int x, int y, int z, Supplier<T> action) {
|
||||
if(delegate.isInRegion(x, y, z)) {
|
||||
return Optional.of(action.get());
|
||||
} else if(warn.getAndSet(false)) {
|
||||
LOGGER.warn("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z,
|
||||
delegate.getCenterChunkX(), delegate.getCenterChunkZ());
|
||||
} else {
|
||||
LOGGER.debug("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z,
|
||||
delegate.getCenterChunkX(), delegate.getCenterChunkZ());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private void access(int x, int y, int z, Runnable action) {
|
||||
if(delegate.isInRegion(x, y, z)) {
|
||||
action.run();
|
||||
} else if(warn.getAndSet(false)) {
|
||||
LOGGER.warn("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z,
|
||||
delegate.getCenterChunkX(), delegate.getCenterChunkZ());
|
||||
} else {
|
||||
LOGGER.debug("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z,
|
||||
delegate.getCenterChunkX(), delegate.getCenterChunkZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.bukkit.BukkitEntity;
|
||||
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.bukkit.world.block.state.BukkitBlockEntity;
|
||||
import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
|
||||
|
||||
|
||||
public class BukkitServerWorld implements ServerWorld {
|
||||
private final org.bukkit.World delegate;
|
||||
|
||||
public BukkitServerWorld(org.bukkit.World delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity spawnEntity(double x, double y, double z, EntityType entityType) {
|
||||
return new BukkitEntity(
|
||||
delegate.spawnEntity(new Location(delegate, x, y, z), ((BukkitEntityType) entityType).getHandle()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
||||
delegate.getBlockAt(x, y, z).setBlockData(BukkitAdapter.adapt(data), physics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return delegate.getSeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return delegate.getMaxHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk getChunkAt(int x, int z) {
|
||||
return BukkitAdapter.adapt(delegate.getChunkAt(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(int x, int y, int z) {
|
||||
return BukkitAdapter.adapt(delegate.getBlockAt(x, y, z).getBlockData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity getBlockEntity(int x, int y, int z) {
|
||||
return BukkitBlockEntity.newInstance(delegate.getBlockAt(x, y, z).getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return delegate.getMinHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getGenerator() {
|
||||
return ((BukkitChunkGeneratorWrapper) delegate.getGenerator()).getHandle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeProvider getBiomeProvider() {
|
||||
return ((BukkitChunkGeneratorWrapper) delegate.getGenerator()).getPack().getBiomeProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return ((BukkitChunkGeneratorWrapper) delegate.getGenerator()).getPack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.World getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return delegate.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof BukkitServerWorld other)) return false;
|
||||
return other.getHandle().equals(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return delegate.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.dfsek.terra.bukkit.world;
|
||||
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
|
||||
public class BukkitWorldProperties implements WorldProperties {
|
||||
private final WorldInfo delegate;
|
||||
|
||||
public BukkitWorldProperties(WorldInfo delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return delegate.getSeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return delegate.getMaxHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return delegate.getMinHeight();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world.block;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.inventory.Item;
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
|
||||
|
||||
public class BukkitBlockTypeAndItem implements BlockType, Item {
|
||||
private final Material delegate;
|
||||
|
||||
public BukkitBlockTypeAndItem(Material delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getDefaultState() {
|
||||
return BukkitAdapter.adapt(delegate.createBlockData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid() {
|
||||
return delegate.isOccluding();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWater() {
|
||||
return delegate == Material.WATER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack newItemStack(int amount) {
|
||||
return BukkitAdapter.adapt(new org.bukkit.inventory.ItemStack(delegate, amount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxDurability() {
|
||||
return delegate.getMaxDurability();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return delegate.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof BukkitBlockTypeAndItem)) return false;
|
||||
return delegate == ((BukkitBlockTypeAndItem) obj).delegate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world.block.data;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
|
||||
|
||||
public class BukkitBlockState implements BlockState {
|
||||
private org.bukkit.block.data.BlockData delegate;
|
||||
|
||||
protected BukkitBlockState(org.bukkit.block.data.BlockData delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
public static BlockState newInstance(org.bukkit.block.data.BlockData bukkitData) {
|
||||
return new BukkitBlockState(bukkitData);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public org.bukkit.block.data.BlockData getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BlockState data) {
|
||||
return delegate.getMaterial() == ((BukkitBlockState) data).getHandle().getMaterial();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Comparable<T>> boolean has(Property<T> property) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Comparable<T>> T get(Property<T> property) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Comparable<T>> BlockState set(Property<T> property, T value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockType getBlockType() {
|
||||
return BukkitAdapter.adapt(delegate.getMaterial());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString(boolean properties) {
|
||||
return delegate.getAsString(!properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAir() {
|
||||
return delegate.getMaterial().isAir();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world.block.state;
|
||||
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
|
||||
|
||||
|
||||
public class BukkitBlockEntity implements BlockEntity {
|
||||
private final org.bukkit.block.BlockState delegate;
|
||||
|
||||
protected BukkitBlockEntity(org.bukkit.block.BlockState block) {
|
||||
this.delegate = block;
|
||||
}
|
||||
|
||||
public static BukkitBlockEntity newInstance(org.bukkit.block.BlockState block) {
|
||||
if(block instanceof Container) return new BukkitContainer((Container) block);
|
||||
if(block instanceof Sign) return new BukkitSign((Sign) block);
|
||||
if(block instanceof CreatureSpawner) return new BukkitMobSpawner((CreatureSpawner) block);
|
||||
return new BukkitBlockEntity(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.block.BlockState getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean applyPhysics) {
|
||||
return delegate.update(true, applyPhysics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 getPosition() {
|
||||
return BukkitAdapter.adapt(delegate.getBlock().getLocation().toVector());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return delegate.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
return delegate.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return delegate.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState() {
|
||||
return BukkitBlockState.newInstance(delegate.getBlockData());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world.block.state;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.Container;
|
||||
import com.dfsek.terra.api.inventory.Inventory;
|
||||
import com.dfsek.terra.bukkit.world.inventory.BukkitInventory;
|
||||
|
||||
|
||||
public class BukkitContainer extends BukkitBlockEntity implements Container {
|
||||
|
||||
protected BukkitContainer(org.bukkit.block.Container block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return new BukkitInventory(((org.bukkit.block.Container) getHandle()).getInventory());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean applyPhysics) {
|
||||
return false; // This clears the inventory. we don't want that.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world.block.state;
|
||||
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.MobSpawner;
|
||||
import com.dfsek.terra.api.block.entity.SerialState;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
|
||||
|
||||
|
||||
public class BukkitMobSpawner extends BukkitBlockEntity implements MobSpawner {
|
||||
protected BukkitMobSpawner(CreatureSpawner block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getSpawnedType() {
|
||||
return new BukkitEntityType(((CreatureSpawner) getHandle()).getSpawnedType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpawnedType(@NotNull EntityType creatureType) {
|
||||
((CreatureSpawner) getHandle()).setSpawnedType(((BukkitEntityType) creatureType).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDelay() {
|
||||
return ((CreatureSpawner) getHandle()).getDelay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDelay(int delay) {
|
||||
((CreatureSpawner) getHandle()).setDelay(delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinSpawnDelay() {
|
||||
return ((CreatureSpawner) getHandle()).getMinSpawnDelay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMinSpawnDelay(int delay) {
|
||||
((CreatureSpawner) getHandle()).setMinSpawnDelay(delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSpawnDelay() {
|
||||
return ((CreatureSpawner) getHandle()).getMaxSpawnDelay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxSpawnDelay(int delay) {
|
||||
((CreatureSpawner) getHandle()).setMaxSpawnDelay(delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSpawnCount() {
|
||||
return ((CreatureSpawner) getHandle()).getSpawnCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpawnCount(int spawnCount) {
|
||||
((CreatureSpawner) getHandle()).setSpawnCount(spawnCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxNearbyEntities() {
|
||||
return ((CreatureSpawner) getHandle()).getMaxNearbyEntities();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxNearbyEntities(int maxNearbyEntities) {
|
||||
((CreatureSpawner) getHandle()).setMaxNearbyEntities(maxNearbyEntities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPlayerRange() {
|
||||
return ((CreatureSpawner) getHandle()).getRequiredPlayerRange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRequiredPlayerRange(int requiredPlayerRange) {
|
||||
((CreatureSpawner) getHandle()).setRequiredPlayerRange(requiredPlayerRange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSpawnRange() {
|
||||
return ((CreatureSpawner) getHandle()).getSpawnRange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpawnRange(int spawnRange) {
|
||||
((CreatureSpawner) getHandle()).setSpawnRange(spawnRange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyState(String state) {
|
||||
SerialState.parse(state).forEach((k, v) -> {
|
||||
switch(k) {
|
||||
case "type" -> setSpawnedType(new BukkitEntityType(org.bukkit.entity.EntityType.valueOf(v.toUpperCase())));
|
||||
case "delay" -> setDelay(Integer.parseInt(v));
|
||||
case "min_delay" -> setMinSpawnDelay(Integer.parseInt(v));
|
||||
case "max_delay" -> setMaxSpawnDelay(Integer.parseInt(v));
|
||||
case "spawn_count" -> setSpawnCount(Integer.parseInt(v));
|
||||
case "spawn_range" -> setSpawnRange(Integer.parseInt(v));
|
||||
case "max_nearby" -> setMaxNearbyEntities(Integer.parseInt(v));
|
||||
case "required_player_range" -> setRequiredPlayerRange(Integer.parseInt(v));
|
||||
default -> throw new IllegalArgumentException("Invalid property: " + k);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world.block.state;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.SerialState;
|
||||
import com.dfsek.terra.api.block.entity.Sign;
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class BukkitSign extends BukkitBlockEntity implements Sign {
|
||||
protected BukkitSign(org.bukkit.block.Sign block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
|
||||
((org.bukkit.block.Sign) getHandle()).setLine(index, line);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String[] getLines() {
|
||||
return ((org.bukkit.block.Sign) getHandle()).getLines();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getLine(int index) throws IndexOutOfBoundsException {
|
||||
return ((org.bukkit.block.Sign) getHandle()).getLine(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyState(String state) {
|
||||
SerialState.parse(state).forEach((k, v) -> {
|
||||
if(!k.startsWith("text")) throw new IllegalArgumentException("Invalid property: " + k);
|
||||
setLine(Integer.parseInt(k.substring(4)), v);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world.entity;
|
||||
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
|
||||
|
||||
public class BukkitEntityType implements EntityType {
|
||||
private final org.bukkit.entity.EntityType delegate;
|
||||
|
||||
public BukkitEntityType(org.bukkit.entity.EntityType delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.EntityType getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world.inventory;
|
||||
|
||||
import com.dfsek.terra.api.inventory.Inventory;
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
|
||||
|
||||
public class BukkitInventory implements Inventory {
|
||||
private final org.bukkit.inventory.Inventory delegate;
|
||||
|
||||
public BukkitInventory(org.bukkit.inventory.Inventory delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int slot, ItemStack newStack) {
|
||||
delegate.setItem(slot, ((BukkitItemStack) newStack).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return delegate.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int slot) {
|
||||
org.bukkit.inventory.ItemStack itemStack = delegate.getItem(slot);
|
||||
return itemStack == null ? null : new BukkitItemStack(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.Inventory getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world.inventory;
|
||||
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.api.inventory.item.ItemMeta;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
import com.dfsek.terra.bukkit.world.inventory.meta.BukkitDamageable;
|
||||
import com.dfsek.terra.bukkit.world.inventory.meta.BukkitEnchantment;
|
||||
|
||||
|
||||
public class BukkitItemMeta implements ItemMeta {
|
||||
private final org.bukkit.inventory.meta.ItemMeta delegate;
|
||||
|
||||
protected BukkitItemMeta(org.bukkit.inventory.meta.ItemMeta delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
public static BukkitItemMeta newInstance(org.bukkit.inventory.meta.ItemMeta delegate) {
|
||||
if(delegate instanceof Damageable) return new BukkitDamageable((Damageable) delegate);
|
||||
return new BukkitItemMeta(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.meta.ItemMeta getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEnchantment(Enchantment enchantment, int level) {
|
||||
delegate.addEnchant(((BukkitEnchantment) enchantment).getHandle(), level, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Enchantment, Integer> getEnchantments() {
|
||||
Map<Enchantment, Integer> map = new HashMap<>();
|
||||
delegate.getEnchants().forEach((enchantment, integer) -> map.put(BukkitAdapter.adapt(enchantment), integer));
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world.inventory;
|
||||
|
||||
import com.dfsek.terra.api.inventory.Item;
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
import com.dfsek.terra.api.inventory.item.ItemMeta;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
|
||||
|
||||
public class BukkitItemStack implements ItemStack {
|
||||
private final org.bukkit.inventory.ItemStack delegate;
|
||||
|
||||
public BukkitItemStack(org.bukkit.inventory.ItemStack delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return delegate.getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAmount(int i) {
|
||||
delegate.setAmount(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getType() {
|
||||
return BukkitAdapter.adapt(delegate.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemMeta getItemMeta() {
|
||||
return BukkitItemMeta.newInstance(delegate.getItemMeta());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemMeta(ItemMeta meta) {
|
||||
delegate.setItemMeta(((BukkitItemMeta) meta).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.ItemStack getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world.inventory.meta;
|
||||
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.dfsek.terra.api.inventory.item.Damageable;
|
||||
import com.dfsek.terra.bukkit.world.inventory.BukkitItemMeta;
|
||||
|
||||
|
||||
public class BukkitDamageable extends BukkitItemMeta implements Damageable {
|
||||
public BukkitDamageable(org.bukkit.inventory.meta.Damageable delegate) {
|
||||
super((ItemMeta) delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamage() {
|
||||
return ((org.bukkit.inventory.meta.Damageable) getHandle()).getDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(int damage) {
|
||||
((org.bukkit.inventory.meta.Damageable) getHandle()).setDamage(damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDamage() {
|
||||
return ((org.bukkit.inventory.meta.Damageable) getHandle()).hasDamage();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.bukkit.world.inventory.meta;
|
||||
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.bukkit.world.inventory.BukkitItemStack;
|
||||
|
||||
|
||||
public class BukkitEnchantment implements Enchantment {
|
||||
private final org.bukkit.enchantments.Enchantment delegate;
|
||||
|
||||
public BukkitEnchantment(org.bukkit.enchantments.Enchantment delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.enchantments.Enchantment getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEnchantItem(ItemStack itemStack) {
|
||||
return delegate.canEnchantItem(((BukkitItemStack) itemStack).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean conflictsWith(Enchantment other) {
|
||||
return delegate.conflictsWith(((BukkitEnchantment) other).getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return delegate.getKey().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return delegate.getMaxLevel();
|
||||
}
|
||||
}
|
||||
8
platforms/bukkit/common/src/main/resources/plugin.yml
Normal file
8
platforms/bukkit/common/src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
name: "Terra"
|
||||
main: "com.dfsek.terra.bukkit.TerraBukkitPlugin"
|
||||
version: "@VERSION@"
|
||||
load: "STARTUP"
|
||||
author: dfsek
|
||||
website: "@WIKI@"
|
||||
api-version: "1.13"
|
||||
description: "@DESCRIPTION@"
|
||||
Reference in New Issue
Block a user