Skip to content

Commit afe4edb

Browse files
committed
Update to 1.16
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.
1 parent f0388aa commit afe4edb

24 files changed

+427
-709
lines changed

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.nitnelave.CreeperHeal</groupId>
55
<artifactId>CreeperHeal</artifactId>
6-
<version>7.0.5</version>
6+
<version>8.0.0</version>
77
<name>CreeperHeal</name>
88

99
<licenses>
@@ -172,10 +172,10 @@
172172
</dependency>
173173
<!--Spigot API-->
174174
<dependency>
175-
<groupId>org.spigotmc</groupId>
176-
<artifactId>spigot-api</artifactId>
177-
<version>1.11-R0.1-SNAPSHOT</version>
178-
<scope>provided</scope>
175+
<groupId>org.spigotmc</groupId>
176+
<artifactId>spigot-api</artifactId>
177+
<version>1.16.3-R0.1-SNAPSHOT</version>
178+
<scope>provided</scope>
179179
</dependency>
180180
</dependencies>
181181
</project>
Lines changed: 19 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,74 @@
11
package com.nitnelave.CreeperHeal.block;
22

33
import org.bukkit.block.Block;
4+
import org.bukkit.Material;
45

56
/**
67
* A utility class to represent a block type along with optional data.
7-
*
8+
*
89
* @author nitnelave
9-
*
10+
*
1011
*/
1112
public class BlockId
1213
{
13-
private int id;
14-
private byte data;
15-
private boolean hasData;
14+
private Material type;
1615

1716
/**
1817
* Only id is specified, data comparison accepts any value.
19-
*
18+
*
2019
* @param id
2120
* The block id.
2221
*/
23-
public BlockId(int id)
22+
public BlockId(Material type)
2423
{
25-
this(id, (byte) -1);
26-
}
27-
28-
/**
29-
* Id and data are specified. If data == -1, then it is considered as
30-
* unspecified.
31-
*
32-
* @param id
33-
* The block id.
34-
* @param data
35-
* The block data.
36-
*/
37-
public BlockId(int id, byte data)
38-
{
39-
this(id, data, data != -1);
40-
}
41-
42-
/**
43-
* Id and data are specified, and hasData specifies if the data is used.
44-
*
45-
* @param id
46-
* The block id.
47-
* @param data
48-
* The block data.
49-
* @param hasData
50-
* Whether the data should be used in comparing.
51-
*/
52-
public BlockId(int id, byte data, boolean hasData)
53-
{
54-
this.id = id;
55-
this.data = data;
56-
this.hasData = hasData && data != -1;
24+
this.type = type;
5725
}
5826

5927
/**
6028
* Constructor from string. The string is parsed in an attempt to get the
6129
* info. The string format accepted is a simple number for just the id, or
6230
* id:data for both.
63-
*
31+
*
6432
* @param str
6533
* The string to be parsed.
6634
* @throws NumberFormatException
6735
* If the string does not match any pattern.
6836
*/
6937
public BlockId(String str) throws NumberFormatException
7038
{
71-
String res = str.trim();
72-
try
73-
{
74-
id = Integer.parseInt(res);
75-
data = -1;
76-
hasData = false;
77-
} catch (NumberFormatException e)
78-
{
79-
String[] split = res.split(":");
80-
if (split.length == 2)
81-
{
82-
id = Integer.parseInt(split[0]);
83-
data = Byte.parseByte(split[1]);
84-
hasData = true;
85-
}
86-
else
87-
throw new NumberFormatException();
88-
}
39+
type = Material.valueOf(str.trim());
8940
}
9041

9142
/**
9243
* Get the id and data from a block.
93-
*
44+
*
9445
* @param block
9546
* The block.
9647
*/
9748
public BlockId(Block block)
9849
{
99-
this(block.getTypeId(), block.getData());
50+
this(block.getType());
10051
}
10152

102-
/**
103-
* Get the id stored.
104-
*
105-
* @return The id stored.
106-
*/
107-
public int getId()
108-
{
109-
return id;
110-
}
111-
112-
/**
113-
* Get the block data. Check for hasData first.
114-
*
115-
* @return The block data.
116-
*/
117-
public byte getData()
53+
public Material getType()
11854
{
119-
return data;
120-
}
121-
122-
/**
123-
* Whether the block's data is used in comparing.
124-
*
125-
* @return Whether the block's data is used in comparing.
126-
*/
127-
public boolean hasData()
128-
{
129-
return hasData;
55+
return type;
13056
}
13157

13258
/*
13359
* (non-Javadoc)
134-
*
60+
*
13561
* @see java.lang.Object#toString()
13662
*/
13763
@Override
13864
public String toString()
13965
{
140-
String str = String.valueOf(id);
141-
if (hasData)
142-
str += ":" + String.valueOf(data);
143-
return str;
66+
return getType().toString();
14467
}
14568

14669
/*
14770
* (non-Javadoc)
148-
*
71+
*
14972
* @see java.lang.Object#equals(java.lang.Object)
15073
*/
15174
@Override
@@ -158,23 +81,17 @@ public boolean equals(Object obj)
15881
return false;
15982

16083
BlockId block = (BlockId) obj;
161-
if (block.id != id)
162-
return false;
163-
//same id
164-
if (!(block.hasData && hasData))
165-
return true;
166-
//both have data
167-
return block.data == data;
84+
return block.type == type;
16885
}
16986

17087
/*
17188
* (non-Javadoc)
172-
*
89+
*
17390
* @see java.lang.Object#hashCode()
17491
*/
17592
@Override
17693
public int hashCode()
17794
{
178-
return id;
95+
return type.hashCode();
17996
}
18097
}

src/main/java/com/nitnelave/CreeperHeal/block/CreeperBanner.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/main/java/com/nitnelave/CreeperHeal/block/CreeperBed.java

Lines changed: 15 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,83 +4,42 @@
44
import org.bukkit.block.Block;
55
import org.bukkit.block.BlockFace;
66
import org.bukkit.block.BlockState;
7-
import org.bukkit.material.Bed;
7+
import org.bukkit.block.data.type.Bed;
88

99
import java.util.ArrayList;
1010
import java.util.List;
1111

1212
/**
1313
* Bed implementation of CreeperBlock.
14-
*
14+
*
1515
* @author nitnelave
16-
*
16+
*
1717
*/
18-
class CreeperBed extends CreeperBlock
18+
class CreeperBed extends CreeperMultiblock
1919
{
20-
21-
/*
22-
* The direction the bed is facing.
23-
*/
24-
private final BlockFace orientation;
25-
20+
private final Bed bedData;
2621
/*
2722
* Constructor.
2823
*/
2924
CreeperBed(BlockState blockState)
3025
{
3126
super(blockState);
32-
Bed bedData = castData(blockState, Bed.class);
33-
orientation = bedData.getFacing();
27+
Bed bedData = (Bed) blockData;
3428
Block block = blockState.getBlock();
35-
if (!bedData.isHeadOfBed())
36-
block = block.getRelative(orientation);
29+
if (bedData.getPart() == Bed.Part.FOOT) {
30+
addDependent(block.getState());
31+
block = block.getRelative(bedData.getFacing());
32+
} else {
33+
addDependent(block.getRelative(bedData.getFacing().getOppositeFace()).getState());
34+
}
3735
this.blockState = block.getState();
38-
}
39-
40-
/**
41-
* The blockstate is always the head of the bed, this gets the foot.
42-
*
43-
* @return the foot of the bed.
44-
*/
45-
public Block getFoot()
46-
{
47-
return getBlock().getRelative(orientation.getOppositeFace());
48-
}
49-
50-
/*
51-
* (non-Javadoc)
52-
*
53-
* @see com.nitnelave.CreeperHeal.block.CreeperBlock#update()
54-
*/
55-
@Override
56-
public void update()
57-
{
58-
super.update();
59-
Block foot = getFoot();
60-
foot.setType(Material.BED_BLOCK, false);
61-
BlockState fs = foot.getState();
62-
Bed d = castData(blockState, Bed.class);
63-
d.setHeadOfBed(false);
64-
d.setFacingDirection(orientation);
65-
fs.setData(d);
66-
fs.update(true, false);
67-
}
68-
69-
/*
70-
* (non-Javadoc)
71-
*
72-
* @see com.nitnelave.CreeperHeal.block.CreeperBlock#remove()
73-
*/
74-
@Override
75-
public void remove()
76-
{
77-
getFoot().setType(Material.AIR, false);
78-
getBlock().setType(Material.AIR, false);
36+
this.blockData = block.getState().getBlockData();
37+
this.bedData = (Bed)this.blockData;
7938
}
8039

8140
/*
8241
* (non-Javadoc)
83-
*
42+
*
8443
* @see com.nitnelave.CreeperHeal.block.CreeperBlock#getNeighbors()
8544
*/
8645
@Override

0 commit comments

Comments
 (0)