Integrated ChunkArchive & added a test for it #13

Merged
NorbiPeti merged 30 commits from dev into master 2018-08-10 20:35:55 +00:00
7 changed files with 118 additions and 9 deletions

11
.idea/misc.xml Normal file
View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project>

26
.travis.yml Normal file
View file

@ -0,0 +1,26 @@
cache:
directories:
- $HOME/.m2/repository/org/
before_install: | # Wget BuildTools and run if cached folder not found
if [ ! -d "$HOME/.m2/repository/org/spigotmc/spigot/1.12.2-R0.1-SNAPSHOT" ]; then
wget -O BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
# grep so that download counts don't appear in log files
java -jar BuildTools.jar --rev 1.12.2 # | grep -vE "[^/ ]*/[^/ ]*\s*KB\s*$" | grep -v "^\s*$"
fi
language: java
jdk:
- oraclejdk8
sudo: required
deploy:
# deploy develop to the staging environment
- provider: script
script: chmod +x deploy.sh && sh deploy.sh staging
on:
branch: dev
skip_cleanup: true
# deploy master to production
- provider: script
script: chmod +x deploy.sh && sh deploy.sh production
on:
branch: master
skip_cleanup: true

2
README_ChunkArchive.md Normal file
View file

@ -0,0 +1,2 @@
# ChunkArchive
Archives chunks as they're populated

11
deploy.sh Normal file
View file

@ -0,0 +1,11 @@
#!/bin/sh
FILENAME=$(find target/ ! -name '*original*' -name '*.jar')
echo Found file: $FILENAME
if [ $1 = 'production' ]; then
echo Production mode
echo $UPLOAD_KEY > upload_key
chmod 400 upload_key
yes | scp -B -i upload_key -o StrictHostKeyChecking=no $FILENAME travis@server.figytuna.com:/minecraft/main/TBMC/pluginupdates
fi

View file

@ -34,8 +34,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version> <version>3.0</version>
<configuration> <configuration>
<source>1.7</source> <source>1.8</source>
<target>1.7</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
@ -63,8 +63,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot</artifactId>
<version>1.11-R0.1-SNAPSHOT</version> <version>1.12.2-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.TBMCPlugins.ButtonCore</groupId> <groupId>com.github.TBMCPlugins.ButtonCore</groupId>

View file

@ -1,14 +1,14 @@
package buttondevteam.presents; package buttondevteam.presents;
import java.util.logging.Logger; import buttondevteam.presents.components.chunkarchive.ChunkArchiveComponent;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import buttondevteam.presents.components.magic.MagicComponent; import buttondevteam.presents.components.magic.MagicComponent;
import buttondevteam.presents.components.research.ResearchComponent; import buttondevteam.presents.components.research.ResearchComponent;
import buttondevteam.presents.components.research.dictionary.DictionaryComponent; import buttondevteam.presents.components.research.dictionary.DictionaryComponent;
import buttondevteam.presents.components.spawn.SpawnComponent; import buttondevteam.presents.components.spawn.SpawnComponent;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.logging.Logger;
public class ButtonPresents extends JavaPlugin{ public class ButtonPresents extends JavaPlugin{
@ -23,6 +23,7 @@ public class ButtonPresents extends JavaPlugin{
new SpawnComponent().register(this); new SpawnComponent().register(this);
new MagicComponent().register(this); new MagicComponent().register(this);
new ResearchComponent().register(this); new ResearchComponent().register(this);
new ChunkArchiveComponent().register(this);
logger.info(pdfFile.getName() + " has fully registered (V." + pdfFile.getVersion()+ ")."); logger.info(pdfFile.getName() + " has fully registered (V." + pdfFile.getVersion()+ ").");
} }

View file

@ -0,0 +1,58 @@
package buttondevteam.presents.components.chunkarchive;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.presents.architecture.Component;
import net.minecraft.server.v1_12_R1.ChunkRegionLoader;
import net.minecraft.server.v1_12_R1.ExceptionWorldConflict;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_12_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkPopulateEvent;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
// @formatter:off
public class ChunkArchiveComponent extends Component implements Listener {
private final File dataFolder = new File("plugins", "ChunkArchive");
@Override
public void register(JavaPlugin plugin) {
try {
this.registerListener(plugin, this);
File testFolder = new File(dataFolder, "test");
testFolder.mkdirs();
Logger logger = plugin.getLogger();
logger.info("Starting chunk save test...");
ChunkRegionLoader testcrl = new ChunkRegionLoader(testFolder,
((CraftServer) Bukkit.getServer()).getServer().dataConverterManager);
CraftWorld mainWorld=(CraftWorld) Bukkit.getWorlds().get(0);
testcrl.saveChunk(mainWorld.getHandle(),
((CraftChunk) mainWorld.getLoadedChunks()[0]).getHandle(), false);
logger.info("Test complete");
}
catch(Exception e) {
TBMCCoreAPI.SendException("ChunkArchive loading/testing failed!", e);
}
}
/*------------------------------------------------------------*/
private final ChunkRegionLoader chunkRegionLoader =
new ChunkRegionLoader(dataFolder,
((CraftServer) Bukkit.getServer()).getServer().dataConverterManager);
/*------------------------------------------------------------*/
@EventHandler
public void onChunkPopulate(ChunkPopulateEvent event) throws IOException, ExceptionWorldConflict
{
if (event.getWorld().getName().equals("world"))
chunkRegionLoader.saveChunk(((CraftWorld) event.getWorld()).getHandle(),
((CraftChunk) event.getChunk()).getHandle(), false);
}
}