Compare commits
17 Commits
9438b1b526
...
v0.1
| Author | SHA1 | Date | |
|---|---|---|---|
| d79d139cae | |||
| f0e8ee791a | |||
| 350858d221 | |||
| 93209ff3f2 | |||
| f8a466a955 | |||
| 46e97dcb43 | |||
| ce00fcf596 | |||
| ecda11b620 | |||
| 9cbfd393ed | |||
| 2a86656188 | |||
| 8bbcc2ae44 | |||
| d7f1759502 | |||
| bfa145b862 | |||
| 8e90d957f7 | |||
| eba9493f63 | |||
| 9ce6ebe8e0 | |||
| c5eae6172c |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,6 +2,8 @@
|
||||
**/build/
|
||||
!src/**/build/
|
||||
dev/container
|
||||
dev/server
|
||||
dev/build
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
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
|
||||
|
||||
## 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
|
||||
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
|
||||
|
||||
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:
|
||||
spigot-dev:
|
||||
image: "nimmis/spigot"
|
||||
container_name: "spigot-dev-hc-revive"
|
||||
container_name: "spigot-dev"
|
||||
environment:
|
||||
- EULA=true
|
||||
- MC_MAXMEM=4g
|
||||
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")
|
||||
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
|
||||
|
||||
@@ -7,40 +7,81 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Skull;
|
||||
import org.bukkit.entity.Player;
|
||||
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.bukkit.util.Vector;
|
||||
import org.kapelle.multiblock.MultiblockListener;
|
||||
import org.kapelle.multiblock.MultiblockStructure;
|
||||
import org.kapelle.multiblock.block_component.IBlockComponent;
|
||||
import org.kapelle.multiblock.block_component.MultipleBlocks;
|
||||
import org.kapelle.multiblock.block_component.SingleBlock;
|
||||
|
||||
public class RevivePlayer implements Listener {
|
||||
private JavaPlugin plugin;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class RevivePlayer{
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
public RevivePlayer(JavaPlugin plugin){
|
||||
this.plugin = plugin;
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event){
|
||||
if(event.getBlockPlaced().getType() == Material.PLAYER_HEAD && !event.isCancelled()){
|
||||
if(isValidMultiblock(event.getBlockPlaced().getLocation())){
|
||||
OfflinePlayer spirit = getPlayerFromHead(event.getBlockPlaced());
|
||||
if (spirit.isOnline() /* && spirit.getPlayer().getGameMode() == GameMode.SPECTATOR */){
|
||||
revivePlayer(spirit.getPlayer(),event.getBlockPlaced().getLocation());
|
||||
}else{
|
||||
// Player is not online or not dead
|
||||
plugin.getServer().broadcastMessage("Player not ded");
|
||||
// TODO
|
||||
}
|
||||
new MultiblockListener(plugin, getMultiblockStructure(), new BlockVector(1, 2, 1)) {
|
||||
@Override
|
||||
protected void callback(Location coreBlockLocation) {
|
||||
onMultiblockValid(coreBlockLocation);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private boolean isValidMultiblock(Location lastPlacedBlock){
|
||||
return lastPlacedBlock.clone().add(new Vector(0,-1,0)).getBlock().getType() == Material.GOLD_BLOCK
|
||||
&& lastPlacedBlock.clone().add(new Vector(0,-2,0)).getBlock().getType() == Material.MAGMA_BLOCK;
|
||||
private MultiblockStructure getMultiblockStructure() {
|
||||
IBlockComponent gold = new SingleBlock(Material.GOLD_BLOCK);
|
||||
IBlockComponent soulSand = new MultipleBlocks(new HashSet<Material>() {{
|
||||
add(Material.SOUL_SAND);
|
||||
add(Material.SOUL_SOIL);
|
||||
}});
|
||||
IBlockComponent head = new SingleBlock(Material.PLAYER_HEAD);
|
||||
IBlockComponent air = new SingleBlock(Material.AIR);
|
||||
IBlockComponent obsidian = new SingleBlock(Material.CRYING_OBSIDIAN);
|
||||
IBlockComponent dia = new SingleBlock(Material.DIAMOND_BLOCK);
|
||||
|
||||
return new MultiblockStructure(
|
||||
Arrays.asList(
|
||||
// Bottom layer
|
||||
Arrays.asList(
|
||||
Arrays.asList(gold, obsidian, gold),
|
||||
Arrays.asList(obsidian, dia, obsidian),
|
||||
Arrays.asList(gold, obsidian, gold)
|
||||
),
|
||||
|
||||
// Mid layer
|
||||
Arrays.asList(
|
||||
Arrays.asList(air, air, air),
|
||||
Arrays.asList(air, soulSand, air),
|
||||
Arrays.asList(air, air, air)
|
||||
|
||||
),
|
||||
|
||||
// Top layer
|
||||
Arrays.asList(
|
||||
Arrays.asList(air, air, air),
|
||||
Arrays.asList(air, head, air),
|
||||
Arrays.asList(air, air, air)
|
||||
)
|
||||
|
||||
));
|
||||
}
|
||||
|
||||
private void onMultiblockValid(Location coreBlockLocation){
|
||||
OfflinePlayer spirit = getPlayerFromHead(coreBlockLocation.getBlock());
|
||||
|
||||
if (spirit.isOnline() /* && spirit.getPlayer().getGameMode() == GameMode.SPECTATOR */){
|
||||
revivePlayer(spirit.getPlayer(),coreBlockLocation);
|
||||
}else{
|
||||
// Player is not online or not dead
|
||||
plugin.getServer().broadcastMessage("Player not ded");
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
private OfflinePlayer getPlayerFromHead(Block head){
|
||||
@@ -51,13 +92,21 @@ public class RevivePlayer implements Listener {
|
||||
private void revivePlayer(Player player, Location headLocation){
|
||||
// Break blocks
|
||||
headLocation.getBlock().setType(Material.AIR);
|
||||
headLocation.add(new Vector(0,-1,0)).getBlock().setType(Material.AIR);
|
||||
headLocation.add(new Vector(0,-1,0)).getBlock().setType(Material.AIR);
|
||||
headLocation.clone().add(0,-1,0).getBlock().setType(Material.AIR);
|
||||
|
||||
for (int x = -1; x < 2; x++) {
|
||||
for (int y = -1; y < 2; y++) {
|
||||
headLocation.clone().add(x,-2,y).getBlock().setType(Material.ANDESITE);
|
||||
}
|
||||
}
|
||||
|
||||
// Teleport player
|
||||
player.teleport(headLocation);
|
||||
|
||||
// Set player gamemode
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
// Set player to 1 heart
|
||||
player.setHealth(2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +1,84 @@
|
||||
package org.kapelle.hardcore_revive;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.Skull;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.kapelle.multiblock.MultiblockListener;
|
||||
import org.kapelle.multiblock.MultiblockStructure;
|
||||
import org.kapelle.multiblock.block_component.IBlockComponent;
|
||||
import org.kapelle.multiblock.block_component.MultipleBlocks;
|
||||
import org.kapelle.multiblock.block_component.SingleBlock;
|
||||
|
||||
public class SummonHead implements Listener {
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class SummonHead{
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
public SummonHead(JavaPlugin plugin){
|
||||
this.plugin = plugin;
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event){
|
||||
if(event.getBlockPlaced().getType() == Material.SOUL_CAMPFIRE && !event.isCancelled()){
|
||||
if (isValidMultiblock(event.getBlockPlaced().getLocation())){
|
||||
summonHead(event.getBlockPlaced().getLocation());
|
||||
new MultiblockListener(plugin, getMultiblockStructure(), new BlockVector(0, 0, 0)) {
|
||||
@Override
|
||||
protected void callback(Location coreBlockLocation) {
|
||||
summonHead(coreBlockLocation);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a block type is a sign that is standing (not mounted on a wall)
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
private boolean isStandingSign(Material block){
|
||||
return block == Material.SPRUCE_SIGN
|
||||
|| block == Material.ACACIA_SIGN
|
||||
|| block == Material.BIRCH_SIGN
|
||||
|| block == Material.CRIMSON_SIGN
|
||||
|| block == Material.DARK_OAK_SIGN
|
||||
|| block == Material.JUNGLE_SIGN
|
||||
|| block == Material.OAK_SIGN
|
||||
|| block == Material.WARPED_SIGN;
|
||||
}
|
||||
private MultiblockStructure getMultiblockStructure(){
|
||||
IBlockComponent sign = new MultipleBlocks(new HashSet<Material>(){{
|
||||
add(Material.SPRUCE_SIGN);
|
||||
add(Material.ACACIA_SIGN);
|
||||
add(Material.CRIMSON_SIGN);
|
||||
add(Material.JUNGLE_SIGN);
|
||||
add(Material.OAK_SIGN);
|
||||
add(Material.WARPED_SIGN);
|
||||
}});
|
||||
|
||||
/**
|
||||
* Checks if the last placed block is a valid multiblock.
|
||||
* The valid structure is from top to bottom: Standing sign, soul sand, soul campfire, soul sand
|
||||
* @param lastBlockLocation Exprected to be the soul campfire
|
||||
* @return if the structure is valid
|
||||
*/
|
||||
private boolean isValidMultiblock(Location lastBlockLocation){
|
||||
return lastBlockLocation.clone().add(new Vector(0,-1,0)).getBlock().getType() == Material.SOUL_SAND
|
||||
&& lastBlockLocation.clone().add(new Vector(0,1,0)).getBlock().getType() == Material.SOUL_SAND
|
||||
&& isStandingSign(lastBlockLocation.clone().add(new Vector(0,2,0)).getBlock().getType());
|
||||
IBlockComponent hayBale = new SingleBlock(Material.HAY_BLOCK);
|
||||
|
||||
IBlockComponent pumpkin = new MultipleBlocks(new HashSet<Material>(){{
|
||||
add(Material.JACK_O_LANTERN);
|
||||
add(Material.CARVED_PUMPKIN);
|
||||
}});
|
||||
|
||||
return new MultiblockStructure(Arrays.asList(
|
||||
// Bottom layer
|
||||
Arrays.asList(
|
||||
Arrays.asList(hayBale)
|
||||
),
|
||||
|
||||
// Mid Layer
|
||||
Arrays.asList(
|
||||
Arrays.asList(pumpkin)
|
||||
),
|
||||
|
||||
// Top layer
|
||||
Arrays.asList(
|
||||
Arrays.asList(sign)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the head summoning ritual.
|
||||
* @param lastBlockLocation The location of the core block of the multiblock structure. In this case
|
||||
* @param coreBlockLocation The location of the core block of the multiblock structure. In this case
|
||||
* the soul campfire.
|
||||
*/
|
||||
private void summonHead(Location lastBlockLocation){
|
||||
Block topBlock = lastBlockLocation.clone().add(new Vector(0,2,0)).getBlock();
|
||||
private void summonHead(Location coreBlockLocation){
|
||||
Location signBlock = coreBlockLocation.clone().add(new Vector(0,2,0));
|
||||
Location pumpkin = coreBlockLocation.clone().add(new Vector(0,1,0));
|
||||
|
||||
String spiritName = getSignText((Sign) topBlock.getState());
|
||||
String spiritName = getSignText((Sign) signBlock.getBlock().getState());
|
||||
Player spirit = plugin.getServer().getPlayerExact(spiritName);
|
||||
|
||||
if (spirit == null) {
|
||||
@@ -79,10 +87,11 @@ public class SummonHead implements Listener {
|
||||
}
|
||||
|
||||
// Remove sign
|
||||
topBlock.setType(Material.AIR);
|
||||
signBlock.getBlock().setType(Material.AIR);
|
||||
pumpkin.getBlock().setType(Material.AIR);
|
||||
|
||||
// Spawn particle at sign
|
||||
topBlock.getWorld().spawnParticle(Particle.SPELL_WITCH,topBlock.getLocation(),20);
|
||||
pumpkin.getWorld().spawnParticle(Particle.SPELL_WITCH,pumpkin,20);
|
||||
|
||||
// Prepare head to be spawned
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
|
||||
@@ -92,11 +101,7 @@ public class SummonHead implements Listener {
|
||||
head.setItemMeta(headMeta);
|
||||
|
||||
// Spawn head at the position of the sign
|
||||
lastBlockLocation.getWorld().dropItem(topBlock.getLocation(),head);
|
||||
|
||||
// Remove soul campfire
|
||||
// FIXME: removing the campfire raises an execption somewhere else. But i think its fine. Maybe removing a tile entity works different
|
||||
lastBlockLocation.getBlock().setType(Material.AIR);
|
||||
pumpkin.getWorld().dropItem(pumpkin,head);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
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