Compare commits
13 Commits
9438b1b526
...
f8a466a955
| Author | SHA1 | Date | |
|---|---|---|---|
| f8a466a955 | |||
| 46e97dcb43 | |||
| ce00fcf596 | |||
| ecda11b620 | |||
| 9cbfd393ed | |||
| 2a86656188 | |||
| 8bbcc2ae44 | |||
| d7f1759502 | |||
| bfa145b862 | |||
| 8e90d957f7 | |||
| eba9493f63 | |||
| 9ce6ebe8e0 | |||
| c5eae6172c |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,6 +2,8 @@
|
|||||||
**/build/
|
**/build/
|
||||||
!src/**/build/
|
!src/**/build/
|
||||||
dev/container
|
dev/container
|
||||||
|
dev/server
|
||||||
|
dev/build
|
||||||
|
|
||||||
# Ignore Gradle GUI config
|
# Ignore Gradle GUI config
|
||||||
gradle-app.setting
|
gradle-app.setting
|
||||||
|
|||||||
15
.idea/runConfigurations/Attach.xml
generated
Normal file
15
.idea/runConfigurations/Attach.xml
generated
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Attach" type="Remote">
|
||||||
|
<option name="USE_SOCKET_TRANSPORT" value="true" />
|
||||||
|
<option name="SERVER_MODE" value="false" />
|
||||||
|
<option name="SHMEM_ADDRESS" />
|
||||||
|
<option name="HOST" value="127.0.0.1" />
|
||||||
|
<option name="PORT" value="5005" />
|
||||||
|
<option name="AUTO_RESTART" value="false" />
|
||||||
|
<RunnerSettings RunnerId="Debug">
|
||||||
|
<option name="DEBUG_PORT" value="5005" />
|
||||||
|
<option name="LOCAL" value="false" />
|
||||||
|
</RunnerSettings>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
@@ -15,6 +15,13 @@ Running gradle from Intellij works fine but from the terminal i had to use
|
|||||||
|
|
||||||
# Dev tools
|
# Dev tools
|
||||||
|
|
||||||
|
## Local Server
|
||||||
|
You can compile the spigot server on your own by running `./buildSpigot.sh 1.16.1` inside the dev directory. The first
|
||||||
|
parameter is the version. If no version is given the `latest` tag is used which is not always the newest minecraft
|
||||||
|
version.
|
||||||
|
|
||||||
|
After that you can start the server and it will run inside the `server` directory.
|
||||||
|
|
||||||
## Server
|
## Server
|
||||||
You can run a spigot server for development. Run `sudo docker-compose up` inside of `dev`.
|
You can run a spigot server for development. Run `sudo docker-compose up` inside of `dev`.
|
||||||
To make inserting the plugin easier change the `SPIGOT_UID` to your UID (run the `id` command). The only problem is
|
To make inserting the plugin easier change the `SPIGOT_UID` to your UID (run the `id` command). The only problem is
|
||||||
|
|||||||
15
dev/buildSpigot.sh
Executable file
15
dev/buildSpigot.sh
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
SCRIPT=$(readlink -f "$0")
|
||||||
|
SCRIPTPATH=$(dirname "$SCRIPT")
|
||||||
|
|
||||||
|
mkdir $SCRIPTPATH/build
|
||||||
|
mkdir $SCRIPTPATH/server
|
||||||
|
|
||||||
|
cd $SCRIPTPATH/build
|
||||||
|
curl -o BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
|
||||||
|
|
||||||
|
java -jar BuildTools.jar --rev ${1:-latest}
|
||||||
|
|
||||||
|
cd $SCRIPTPATH/server
|
||||||
|
echo "eula=true" > eula.txt
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ version: "3"
|
|||||||
services:
|
services:
|
||||||
spigot-dev:
|
spigot-dev:
|
||||||
image: "nimmis/spigot"
|
image: "nimmis/spigot"
|
||||||
container_name: "spigot-dev-hc-revive"
|
container_name: "spigot-dev"
|
||||||
environment:
|
environment:
|
||||||
- EULA=true
|
- EULA=true
|
||||||
- MC_MAXMEM=4g
|
- MC_MAXMEM=4g
|
||||||
@@ -13,4 +13,4 @@ services:
|
|||||||
- "./container:/minecraft"
|
- "./container:/minecraft"
|
||||||
restart: "no"
|
restart: "no"
|
||||||
ports:
|
ports:
|
||||||
- "25565:25565"
|
- "25565:25565"
|
||||||
5
dev/docker/insertPlugin.sh
Executable file
5
dev/docker/insertPlugin.sh
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
SCRIPT=$(readlink -f "$0")
|
||||||
|
SCRIPTPATH=$(dirname "$SCRIPT")
|
||||||
|
|
||||||
|
cp $SCRIPTPATH/../../build/libs/* $SCRIPTPATH/container/plugins
|
||||||
2
dev/docker/log.sh
Executable file
2
dev/docker/log.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
sudo docker exec spigot-dev mc_log
|
||||||
2
dev/docker/restartServer.sh
Executable file
2
dev/docker/restartServer.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
sudo docker exec spigot-dev mc_restart
|
||||||
@@ -2,4 +2,4 @@
|
|||||||
SCRIPT=$(readlink -f "$0")
|
SCRIPT=$(readlink -f "$0")
|
||||||
SCRIPTPATH=$(dirname "$SCRIPT")
|
SCRIPTPATH=$(dirname "$SCRIPT")
|
||||||
|
|
||||||
cp $SCRIPTPATH/../build/libs/* $SCRIPTPATH/container/plugins
|
cp $SCRIPTPATH/../build/libs/* $SCRIPTPATH/server/plugins
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
sudo docker exec spigot-dev-hc-revive mc_log
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
sudo docker exec spigot-dev-hc-revive mc_restart
|
|
||||||
7
dev/startServer.sh
Executable file
7
dev/startServer.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
SCRIPT=$(readlink -f "$0")
|
||||||
|
SCRIPTPATH=$(dirname "$SCRIPT")
|
||||||
|
|
||||||
|
cd $SCRIPTPATH/server
|
||||||
|
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005 -jar $SCRIPTPATH/build/spigot-*.jar nogui
|
||||||
|
|
||||||
44
src/main/java/org/kapelle/multiblock/MultiblockListener.java
Normal file
44
src/main/java/org/kapelle/multiblock/MultiblockListener.java
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package org.kapelle.multiblock;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
|
import org.kapelle.multiblock.block_component.IBlockComponent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listens for block placements and checks if it is part of a the multiblock structure.
|
||||||
|
*/
|
||||||
|
public abstract class MultiblockListener implements Listener {
|
||||||
|
protected final IBlockComponent coreBlock;
|
||||||
|
protected final BlockVector coreBlockOffset;
|
||||||
|
protected final MultiblockStructure structure;
|
||||||
|
|
||||||
|
public MultiblockListener(JavaPlugin plugin, MultiblockStructure structure, BlockVector coreBlockOffset){
|
||||||
|
this.structure = structure;
|
||||||
|
this.coreBlockOffset = coreBlockOffset;
|
||||||
|
|
||||||
|
this.coreBlock = structure.getComponent(coreBlockOffset);
|
||||||
|
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockPlaced(BlockPlaceEvent event){
|
||||||
|
Location placedLocation = event.getBlockPlaced().getLocation();
|
||||||
|
if(!event.isCancelled() && this.coreBlock.isValidBlock(placedLocation)){
|
||||||
|
if(this.structure.isValid(placedLocation,this.coreBlockOffset)){
|
||||||
|
callback(placedLocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets called on successfully validating a multiblock
|
||||||
|
* @param coreBlockLocation location of the core block
|
||||||
|
*/
|
||||||
|
protected abstract void callback(Location coreBlockLocation);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package org.kapelle.multiblock;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
|
import org.kapelle.multiblock.block_component.IBlockComponent;
|
||||||
|
import org.kapelle.multiblock.block_component.ICheckFunction;
|
||||||
|
import org.kapelle.multiblock.constraint.IConstraint;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a full multiblock.
|
||||||
|
* Contains the individual block components.
|
||||||
|
*/
|
||||||
|
public class MultiblockStructure {
|
||||||
|
|
||||||
|
private final List<List<List<IBlockComponent>>> structure;
|
||||||
|
private final List<IConstraint> constraints = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a multiblock structure.
|
||||||
|
* The format is like this: [y][z][x]
|
||||||
|
* So you describe the layers from bottom to top.
|
||||||
|
* @param structure structure in the format: [y][z][x]
|
||||||
|
*/
|
||||||
|
public MultiblockStructure(List<List<List<IBlockComponent>>> structure){
|
||||||
|
this.structure = structure;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IBlockComponent getComponent(BlockVector offset){
|
||||||
|
return getComponent(offset.getBlockX(),offset.getBlockY(),offset.getBlockZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public IBlockComponent getComponent(int x, int y, int z){
|
||||||
|
return structure.get(y).get(z).get(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getBlockLocation(Location location, BlockVector offset, BlockVector localPosition){
|
||||||
|
return location.clone().subtract(offset).add(localPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the multiblock is valid at the given location.
|
||||||
|
* @param location Location of a block in a multiblock structure.
|
||||||
|
* @param offset the offset of the location from <0,0,0>
|
||||||
|
* @return true if valid
|
||||||
|
*/
|
||||||
|
public boolean isValid(Location location, BlockVector offset){
|
||||||
|
for (int y = 0; y < structure.size(); y++) {
|
||||||
|
for (int z = 0; z < structure.get(y).size(); z++) {
|
||||||
|
for (int x = 0; x < structure.get(y).get(z).size() ; x++) {
|
||||||
|
|
||||||
|
IBlockComponent currentComponent = getComponent(x,y,z);
|
||||||
|
Location globalBlockLocation = getBlockLocation(location,offset,new BlockVector(x,y,z));
|
||||||
|
|
||||||
|
if(!currentComponent.isValidBlock(globalBlockLocation)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (IConstraint constraint:constraints) {
|
||||||
|
if(!constraint.isValid(location,offset,this)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addConstraint(IConstraint constraint){
|
||||||
|
this.constraints.add(constraint);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package org.kapelle.multiblock.block_component;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
public class AnyBlock implements IBlockComponent{
|
||||||
|
private static final AnyBlock singleton = new AnyBlock();
|
||||||
|
|
||||||
|
private AnyBlock(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidBlock(Location location) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AnyBlock getInstance(){
|
||||||
|
return AnyBlock.singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package org.kapelle.multiblock.block_component;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a single position in a multiblock.
|
||||||
|
*/
|
||||||
|
public interface IBlockComponent {
|
||||||
|
public boolean isValidBlock(Location location);
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package org.kapelle.multiblock.block_component;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for a custom check function.
|
||||||
|
*/
|
||||||
|
public interface ICheckFunction {
|
||||||
|
boolean apply(Location location);
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package org.kapelle.multiblock.block_component;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
public class LambdaComponent implements IBlockComponent{
|
||||||
|
private final ICheckFunction checkFunction;
|
||||||
|
|
||||||
|
public LambdaComponent(ICheckFunction checkFunction){
|
||||||
|
this.checkFunction = checkFunction;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidBlock(Location location) {
|
||||||
|
return checkFunction.apply(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package org.kapelle.multiblock.block_component;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class MultipleBlocks implements IBlockComponent{
|
||||||
|
private final Set<Material> validMaterial;
|
||||||
|
|
||||||
|
public MultipleBlocks(Set<Material> validMaterial){
|
||||||
|
this.validMaterial = validMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidBlock(Location location) {
|
||||||
|
return this.validMaterial.contains(location.getBlock().getType());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package org.kapelle.multiblock.block_component;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
public class SingleBlock implements IBlockComponent{
|
||||||
|
private final Material material;
|
||||||
|
|
||||||
|
public SingleBlock(Material material){
|
||||||
|
this.material = material;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidBlock(Location location) {
|
||||||
|
return location.getBlock().getType() == this.material;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package org.kapelle.multiblock.constraint;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
|
import org.kapelle.multiblock.MultiblockStructure;
|
||||||
|
|
||||||
|
public interface IConstraint {
|
||||||
|
public boolean isValid(Location coreBlockLocation, BlockVector offset, MultiblockStructure structure);
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package org.kapelle.multiblock.constraint;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
|
import org.kapelle.multiblock.MultiblockStructure;
|
||||||
|
|
||||||
|
import java.security.InvalidParameterException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SameBlockConstraint implements IConstraint{
|
||||||
|
|
||||||
|
private final List<BlockVector> positions;
|
||||||
|
|
||||||
|
public SameBlockConstraint(List<BlockVector> positions){
|
||||||
|
this.positions = positions;
|
||||||
|
if (positions.size() <= 1){
|
||||||
|
throw new InvalidParameterException("position need at least 2 positions");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(Location coreBlockLocation, BlockVector offset, MultiblockStructure structure) {
|
||||||
|
Material material = structure.getBlockLocation(coreBlockLocation,offset,positions.get(0)).getBlock().getType();
|
||||||
|
|
||||||
|
for (BlockVector pos : positions) {
|
||||||
|
if(structure.getBlockLocation(coreBlockLocation,offset,pos).getBlock().getType() != material){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user