init
This commit is contained in:
136
minecart/pom.xml
Normal file
136
minecart/pom.xml
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>plugin.minecraft</groupId>
|
||||||
|
<artifactId>minecart</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<name>minecart</name>
|
||||||
|
<!-- FIXME change it to the project's website -->
|
||||||
|
<url>http://www.example.com</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>papermc</id>
|
||||||
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<repository>
|
||||||
|
<id>spigot-nexus</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
-->
|
||||||
|
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.11</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.18-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.papermc.paper</groupId>
|
||||||
|
<artifactId>paper-api</artifactId>
|
||||||
|
<version>1.18.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>bukkit</artifactId>
|
||||||
|
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
|
||||||
|
<sourceDirectory>${project.basedir}/src/main/java/plugin/minecraft</sourceDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${project.basedir}/src/main/resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>plugin.yml</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
|
|
||||||
|
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||||
|
<plugins>
|
||||||
|
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</plugin>
|
||||||
|
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.0</version>
|
||||||
|
<configuration>
|
||||||
|
<release>17</release>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
|
<version>2.5.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>2.8.2</version>
|
||||||
|
</plugin>
|
||||||
|
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
<version>3.7.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
25
minecart/src/main/java/plugin/minecraft/Main.java
Normal file
25
minecart/src/main/java/plugin/minecraft/Main.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package plugin.minecraft;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hello world!
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Main extends JavaPlugin {
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
getLogger().info("Hello, SpigotMC! sadae");
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvents(new MinecartMove(this), this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
getLogger().info("See you again, SpigotMC!");
|
||||||
|
}
|
||||||
|
}
|
||||||
92
minecart/src/main/java/plugin/minecraft/MinecartMove.java
Normal file
92
minecart/src/main/java/plugin/minecraft/MinecartMove.java
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
package plugin.minecraft;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.vehicle.VehicleCreateEvent;
|
||||||
|
import org.bukkit.event.vehicle.VehicleMoveEvent;
|
||||||
|
import org.bukkit.event.world.ChunkLoadEvent;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class MinecartMove implements Listener {
|
||||||
|
|
||||||
|
private Plugin plugin;
|
||||||
|
|
||||||
|
MinecartMove(Plugin p) {
|
||||||
|
plugin = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onVehicleCreate(VehicleCreateEvent ev) {
|
||||||
|
ev.getVehicle().setVelocity(new Vector(1.0, 0.0, 0.0));
|
||||||
|
|
||||||
|
if (ev.getVehicle().getType() == EntityType.MINECART_CHEST) {
|
||||||
|
Bukkit.getLogger().info(String.format("Minecart %d %s", ev.getVehicle().getChunk().getX(),
|
||||||
|
ev.getVehicle().getChunk().getX()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
void onVehicleMove(VehicleMoveEvent ev) {
|
||||||
|
var vehicle = ev.getVehicle();
|
||||||
|
if (vehicle.getType() == EntityType.MINECART_CHEST) {
|
||||||
|
var x = vehicle.getChunk().getX();
|
||||||
|
var z = vehicle.getChunk().getZ();
|
||||||
|
|
||||||
|
var world = vehicle.getWorld();
|
||||||
|
|
||||||
|
var vel = vehicle.getVelocity();
|
||||||
|
|
||||||
|
// plugin.getLogger().info(String.format("Current %d %d", x, z));
|
||||||
|
|
||||||
|
var chunk = vehicle.getChunk();
|
||||||
|
if (!chunk.getPluginChunkTickets().contains(plugin)) {
|
||||||
|
plugin.getLogger().info(String.format("Loading %d %d", x, z));
|
||||||
|
chunk.addPluginChunkTicket(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
var last_x = x;
|
||||||
|
var last_z = z;
|
||||||
|
var next_x = x;
|
||||||
|
var next_z = z;
|
||||||
|
|
||||||
|
if (vel.getX() > 0) {
|
||||||
|
last_x -= 2;
|
||||||
|
next_x += 1;
|
||||||
|
} else if (vel.getX() < 0) {
|
||||||
|
last_x += 2;
|
||||||
|
next_x -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vel.getZ() > 0) {
|
||||||
|
last_z -= 2;
|
||||||
|
next_z += 1;
|
||||||
|
} else if (vel.getZ() < 0) {
|
||||||
|
last_z += 2;
|
||||||
|
next_z -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world.getPluginChunkTickets(next_x, next_z).contains(plugin)) {
|
||||||
|
plugin.getLogger().info(String.format("Loading %d %d", next_x, next_z));
|
||||||
|
world.addPluginChunkTicket(next_x, next_z, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (last_x != x || last_z != z) {
|
||||||
|
if (world.getPluginChunkTickets(last_x, last_z).contains(plugin)) {
|
||||||
|
plugin.getLogger().info(String.format("Removing Ticket %d %d", last_x, last_z));
|
||||||
|
world.removePluginChunkTicket(last_x, last_z, plugin);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChunkLoad(ChunkLoadEvent ev) {
|
||||||
|
plugin.getLogger().info(String.format("Chunk Loaded %d %d Chunk Count: %d", ev.getChunk().getX(),
|
||||||
|
ev.getChunk().getZ(), ev.getWorld().getChunkCount()));
|
||||||
|
}
|
||||||
|
}
|
||||||
4
minecart/src/main/resources/plugin.yml
Normal file
4
minecart/src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
main: plugin.minecraft.Main
|
||||||
|
name: minecart
|
||||||
|
version: "0.1"
|
||||||
|
api-version: "1.18"
|
||||||
20
minecart/src/test/java/plugin/minecraft/AppTest.java
Normal file
20
minecart/src/test/java/plugin/minecraft/AppTest.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package plugin.minecraft;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for simple App.
|
||||||
|
*/
|
||||||
|
public class AppTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Rigorous Test :-)
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void shouldAnswerWithTrue()
|
||||||
|
{
|
||||||
|
assertTrue( true );
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user