Skip to content

Commit 82183fa

Browse files
committed
v3.4.3
- Fix bug where selecting floor for first time after elevator creation may throw NullPointerException - Store elev id inside Elevator class to ensure deletion works correctly - Commands ignoring case could cause issues with autocomplete
1 parent 8557083 commit 82183fa

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>net.forestfire</groupId>
77
<artifactId>Elevators</artifactId>
8-
<version>3.4.2</version>
8+
<version>3.4.3</version>
99
<packaging>jar</packaging>
1010
<name>Elevators</name>
1111
<properties>
@@ -50,7 +50,7 @@
5050
<repositories>
5151
<repository>
5252
<id>papermc</id>
53-
<url>https://repo.papermc.io/repository/maven-public/</url>
53+
<url>https://repo.papermc.io/repository/maven-public</url>
5454
</repository>
5555
</repositories>
5656
<dependencies>

src/main/java/net/forestfire/elevators/Conf.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static Object loadConf() { try {
202202
//Load Compressed Elevator Data:
203203
elevators.clear(); ConfigurationSection eList=conf.getConfigurationSection("elevators");
204204
int eCnt=0; if(eList!=null) for(String k: eList.getKeys(false)) {
205-
Elevator e=Elevator.fromSaveData(eList.getStringList(k));
205+
Elevator e=Elevator.fromSaveData(k, eList.getStringList(k));
206206
if(e!=null) elevators.put(k,e);
207207
else { eCnt++; err("loadConfig", "fromSaveData returned null at ID "+k); }
208208
}

src/main/java/net/forestfire/elevators/Elevator.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.bukkit.util.Vector;
1818

1919
public class Elevator {
20+
public final String id;
2021
public Floor floor;
2122
public ChuList<ChuList<Block>> sGroups;
2223
public ChuList<ChuList<Block>> csGroups;
@@ -25,14 +26,14 @@ public class Elevator {
2526

2627
//-- Initialization Functions
2728

28-
public Elevator(Floor _floor, ChuList<ChuList<Block>> _sGroups, ChuList<ChuList<Block>> _csGroups) {
29-
floor=_floor; if(_sGroups==null) sGroups=new ChuList<>(); else sGroups=_sGroups;
29+
public Elevator(String _id, Floor _floor, ChuList<ChuList<Block>> _sGroups, ChuList<ChuList<Block>> _csGroups) {
30+
id=_id; floor=_floor; if(_sGroups==null) sGroups=new ChuList<>(); else sGroups=_sGroups;
3031
if(_csGroups==null) csGroups=new ChuList<>(); else csGroups=_csGroups;
3132
csData = new ChuList<>();
3233
}
3334

3435
//Data Format: [World, Signs1 X, Signs1 Z, Signs2 X, Signs2 Z...]
35-
public static Elevator fromSaveData(java.util.List<String> data) {
36+
public static Elevator fromSaveData(String id, java.util.List<String> data) {
3637
if(data.size() < 3 || data.size() % 2 == 0) { Conf.err("fromSaveData", "Data length too small or not odd number."); return null; }
3738
World w=Bukkit.getServer().getWorld(data.getFirst()); if(w==null) {
3839
Conf.err("fromSaveData", "World '"+data.getFirst()+"' does not exist!"); return null;
@@ -45,7 +46,7 @@ public static Elevator fromSaveData(java.util.List<String> data) {
4546
if(sList.length!=0) sGroups.add(sList);
4647
}
4748
if(sGroups.length==0) { Conf.err("fromSaveData", "No elevator signs found!"); return null; }
48-
Elevator elev = new Elevator(null, sGroups, null); Block dSign = sGroups.getFirst().getFirst();
49+
Elevator elev = new Elevator(id, null, sGroups, null); Block dSign = sGroups.getFirst().getFirst();
4950
Floor f=Floor.getFloor(w.getBlockAt(dSign.getX(), elev.getLevel(true)+2, dSign.getZ()), elev);
5051
if(f==null) { Conf.err("fromSaveData", "No elevator floor detected!"); return null; }
5152
elev.floor=f; elev.rebuildCallSignList(null);
@@ -65,9 +66,11 @@ public ChuList<String> toSaveData() {
6566

6667
//The names Bond. James Bond
6768
public void selfDestruct() {
68-
if(floor != null && sGroups.length>0 && sGroups.getFirst().length>0) { resetElevator(true); setDoors(0,false); }
69-
floor=null; for(ChuList<Block> c: csGroups) for(Block s: c) s.setType(Conf.AIR);
70-
Conf.elevators.entrySet().remove(this);
69+
if(floor != null && sGroups.length>0 && sGroups.getFirst().length>0) {
70+
resetElevator(); setDoors(0,false);
71+
}
72+
for(ChuList<Block> c: csGroups) for(Block s: c) s.setType(Conf.AIR);
73+
floor=null; Conf.elevators.remove(id);
7174
}
7275

7376
public int yMin() { return sGroups.getFirst().getFirst().getY()-2; }
@@ -235,7 +238,7 @@ public void updateFloorName(String flName) {
235238
public FList getFloors() {
236239
ChuList<Block> ds=sGroups.getFirst(); int n=0;
237240
String s,sel=Conf.rc(Conf.line(ds.getFirst(),1));
238-
sel=sel.substring(Conf.L_STL, sel.length()-Conf.L_ENDL);
241+
if(!sel.isEmpty()) sel=sel.substring(Conf.L_STL, sel.length()-Conf.L_ENDL);
239242
int i=0,l=ds.length; ChuList<String> fn=new ChuList<>(l);
240243
for(; i<l; i++) {
241244
fn.add(s=Conf.line(ds.get(i),3));

src/main/java/net/forestfire/elevators/Floor.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public static Floor getFloor(Block b, Elevator parent) {
4747

4848
//Creates Floor or MovingFloor at height 'h'
4949
//If MovingFloor, returns new floorID
50-
//Deletes existing floor blocks unless 'dontDelete' is true
51-
public int addFloor(double h, boolean isMoving, boolean dontDelete, Integer forceID) {
52-
if(!dontDelete) { removeFallingBlocks(); elev.resetElevator(true); }
50+
//Deletes existing floor blocks unless 'noDelete' is true
51+
public int addFloor(double h, boolean isMoving, boolean noDelete, Integer forceID) {
52+
if(!noDelete) { removeFallingBlocks(); elev.resetElevator(true); }
5353
if(isMoving) { //Create FallingBlock Floor
5454
ChuList<FallingBlock> bl=new ChuList<>((xMax-xMin+1)*(zMax-zMin+1)); moving=true;
5555
for(int x=xMin; x<=xMax; x++) for(int z=zMin; z<=zMax; z++) {
@@ -62,8 +62,8 @@ public int addFloor(double h, boolean isMoving, boolean dontDelete, Integer forc
6262
for(int x=xMin; x<=xMax; x++) for(int z=zMin; z<=zMax; z++) world.getBlockAt(x,(int)h,z).setType(fType);
6363
} return 0;
6464
}
65-
public int addFloor(double h, boolean isMoving, boolean dontDelete) {
66-
return addFloor(h, isMoving, dontDelete, null);
65+
public int addFloor(double h, boolean isMoving, boolean noDelete) {
66+
return addFloor(h, isMoving, noDelete, null);
6767
}
6868

6969
//Moves a MovingFloor using floorID

src/main/java/net/forestfire/elevators/Main.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void onDisable() {
4848
}
4949
@Override
5050
public boolean onCommand(@NotNull CommandSender s, Command c, @NotNull String l, String[] a) {
51-
if(c.getName().equalsIgnoreCase("elev")) {
51+
if(c.getName().equals("elev")) {
5252
if(a.length == 1 && a[0].equals("list")) {
5353
Collection<Elevator> el = Conf.elevators.values();
5454
Conf.msg(s, el.size()+" Elevators:");
@@ -150,7 +150,8 @@ private boolean checkLine(SignChangeEvent e, String test) {
150150
Conf.err("onSignChange:ElevSign:NewElev", "Floor not found!"); return;
151151
}
152152
String eID=Conf.locToString(new Location(f.world, f.xMin, 0, f.zMin));
153-
elev=new Elevator(f, null, null); Conf.elevators.put(eID, (f.elev=elev));
153+
elev=new Elevator(eID, f, null, null);
154+
Conf.elevators.put(eID, (f.elev=elev));
154155
sList=Elevator.rebuildSignList(sign); Conf.msg(e.getPlayer(), "&eElevator created.");
155156
}
156157

0 commit comments

Comments
 (0)