Skip to content

Commit

Permalink
Update to 1.16
Browse files Browse the repository at this point in the history
Use the new Materials and the new BlockData in a lot of places. I didn't
check that everything works, and I know that rails don't come back like
they were before, or that glass panes and double chests don't reattach
perfectly. I didn't update the properties of many new blocks (lantern
has to be placed after the blocks above and below, soul torch is like a
torch and so on). But overall, it should do 95% of the job right, which
is still better than no plugin.
  • Loading branch information
nitnelave committed Oct 27, 2020
1 parent f0388aa commit afe4edb
Show file tree
Hide file tree
Showing 24 changed files with 427 additions and 709 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.nitnelave.CreeperHeal</groupId>
<artifactId>CreeperHeal</artifactId>
<version>7.0.5</version>
<version>8.0.0</version>
<name>CreeperHeal</name>

<licenses>
Expand Down Expand Up @@ -172,10 +172,10 @@
</dependency>
<!--Spigot API-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.11-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
121 changes: 19 additions & 102 deletions src/main/java/com/nitnelave/CreeperHeal/block/BlockId.java
Original file line number Diff line number Diff line change
@@ -1,151 +1,74 @@
package com.nitnelave.CreeperHeal.block;

import org.bukkit.block.Block;
import org.bukkit.Material;

/**
* A utility class to represent a block type along with optional data.
*
*
* @author nitnelave
*
*
*/
public class BlockId
{
private int id;
private byte data;
private boolean hasData;
private Material type;

/**
* Only id is specified, data comparison accepts any value.
*
*
* @param id
* The block id.
*/
public BlockId(int id)
public BlockId(Material type)
{
this(id, (byte) -1);
}

/**
* Id and data are specified. If data == -1, then it is considered as
* unspecified.
*
* @param id
* The block id.
* @param data
* The block data.
*/
public BlockId(int id, byte data)
{
this(id, data, data != -1);
}

/**
* Id and data are specified, and hasData specifies if the data is used.
*
* @param id
* The block id.
* @param data
* The block data.
* @param hasData
* Whether the data should be used in comparing.
*/
public BlockId(int id, byte data, boolean hasData)
{
this.id = id;
this.data = data;
this.hasData = hasData && data != -1;
this.type = type;
}

/**
* Constructor from string. The string is parsed in an attempt to get the
* info. The string format accepted is a simple number for just the id, or
* id:data for both.
*
*
* @param str
* The string to be parsed.
* @throws NumberFormatException
* If the string does not match any pattern.
*/
public BlockId(String str) throws NumberFormatException
{
String res = str.trim();
try
{
id = Integer.parseInt(res);
data = -1;
hasData = false;
} catch (NumberFormatException e)
{
String[] split = res.split(":");
if (split.length == 2)
{
id = Integer.parseInt(split[0]);
data = Byte.parseByte(split[1]);
hasData = true;
}
else
throw new NumberFormatException();
}
type = Material.valueOf(str.trim());
}

/**
* Get the id and data from a block.
*
*
* @param block
* The block.
*/
public BlockId(Block block)
{
this(block.getTypeId(), block.getData());
this(block.getType());
}

/**
* Get the id stored.
*
* @return The id stored.
*/
public int getId()
{
return id;
}

/**
* Get the block data. Check for hasData first.
*
* @return The block data.
*/
public byte getData()
public Material getType()
{
return data;
}

/**
* Whether the block's data is used in comparing.
*
* @return Whether the block's data is used in comparing.
*/
public boolean hasData()
{
return hasData;
return type;
}

/*
* (non-Javadoc)
*
*
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
String str = String.valueOf(id);
if (hasData)
str += ":" + String.valueOf(data);
return str;
return getType().toString();
}

/*
* (non-Javadoc)
*
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
Expand All @@ -158,23 +81,17 @@ public boolean equals(Object obj)
return false;

BlockId block = (BlockId) obj;
if (block.id != id)
return false;
//same id
if (!(block.hasData && hasData))
return true;
//both have data
return block.data == data;
return block.type == type;
}

/*
* (non-Javadoc)
*
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode()
{
return id;
return type.hashCode();
}
}
43 changes: 0 additions & 43 deletions src/main/java/com/nitnelave/CreeperHeal/block/CreeperBanner.java

This file was deleted.

71 changes: 15 additions & 56 deletions src/main/java/com/nitnelave/CreeperHeal/block/CreeperBed.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,83 +4,42 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.material.Bed;
import org.bukkit.block.data.type.Bed;

import java.util.ArrayList;
import java.util.List;

/**
* Bed implementation of CreeperBlock.
*
*
* @author nitnelave
*
*
*/
class CreeperBed extends CreeperBlock
class CreeperBed extends CreeperMultiblock
{

/*
* The direction the bed is facing.
*/
private final BlockFace orientation;

private final Bed bedData;
/*
* Constructor.
*/
CreeperBed(BlockState blockState)
{
super(blockState);
Bed bedData = castData(blockState, Bed.class);
orientation = bedData.getFacing();
Bed bedData = (Bed) blockData;
Block block = blockState.getBlock();
if (!bedData.isHeadOfBed())
block = block.getRelative(orientation);
if (bedData.getPart() == Bed.Part.FOOT) {
addDependent(block.getState());
block = block.getRelative(bedData.getFacing());
} else {
addDependent(block.getRelative(bedData.getFacing().getOppositeFace()).getState());
}
this.blockState = block.getState();
}

/**
* The blockstate is always the head of the bed, this gets the foot.
*
* @return the foot of the bed.
*/
public Block getFoot()
{
return getBlock().getRelative(orientation.getOppositeFace());
}

/*
* (non-Javadoc)
*
* @see com.nitnelave.CreeperHeal.block.CreeperBlock#update()
*/
@Override
public void update()
{
super.update();
Block foot = getFoot();
foot.setType(Material.BED_BLOCK, false);
BlockState fs = foot.getState();
Bed d = castData(blockState, Bed.class);
d.setHeadOfBed(false);
d.setFacingDirection(orientation);
fs.setData(d);
fs.update(true, false);
}

/*
* (non-Javadoc)
*
* @see com.nitnelave.CreeperHeal.block.CreeperBlock#remove()
*/
@Override
public void remove()
{
getFoot().setType(Material.AIR, false);
getBlock().setType(Material.AIR, false);
this.blockData = block.getState().getBlockData();
this.bedData = (Bed)this.blockData;
}

/*
* (non-Javadoc)
*
*
* @see com.nitnelave.CreeperHeal.block.CreeperBlock#getNeighbors()
*/
@Override
Expand Down
Loading

0 comments on commit afe4edb

Please sign in to comment.