Skip to content

Commit a580661

Browse files
author
BastouP411
committed
Corrected obfuscation problem
1 parent a22c22d commit a580661

File tree

17 files changed

+161
-133
lines changed

17 files changed

+161
-133
lines changed

src/main/java/fr/bastoup/bperipherals/database/DBUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package fr.bastoup.bperipherals.database;
22

3-
import dan200.computercraft.api.lua.LuaException;
43
import fr.bastoup.bperipherals.beans.ErrorResult;
54
import fr.bastoup.bperipherals.beans.QueryResult;
65
import fr.bastoup.bperipherals.beans.SQLResult;
@@ -34,7 +33,7 @@ public static List<Map<String, Object>> mapResults(ResultSet resultSet) throws S
3433
tableList.add(rows);
3534
}
3635

37-
List<Map<String, Object>> res = new ArrayList<Map<String, Object>>();
36+
List<Map<String, Object>> res = new ArrayList<>();
3837
for (Object[] r : tableList) {
3938
res.add(map(keys, r));
4039
}
@@ -49,7 +48,7 @@ public static Map<String, Object> map(String[] keys, Object[] values) {
4948
return hMap;
5049
}
5150

52-
public static List<Object> factorizeResults(SQLResult res) throws LuaException {
51+
public static List<Object> factorizeResults(SQLResult res) {
5352
List<Object> ret = new ArrayList<>();
5453
if (res instanceof QueryResult) {
5554
ret.add("query");
@@ -58,7 +57,8 @@ public static List<Object> factorizeResults(SQLResult res) throws LuaException {
5857
ret.add("update");
5958
ret.add(((UpdateResult) res).getUpdateCount());
6059
} else if (res instanceof ErrorResult) {
61-
throw new LuaException(((ErrorResult) res).getError());
60+
ret.add("error");
61+
ret.add(((ErrorResult) res).getError());
6262
}
6363
return ret;
6464
}

src/main/java/fr/bastoup/bperipherals/init/ModBlocks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.util.List;
1111

1212
public class ModBlocks {
13-
public static final List<Block> BLOCKS = new ArrayList<Block>();
13+
public static final List<Block> BLOCKS = new ArrayList<>();
1414

1515
public static final Block FE_METER = new BlockFEMeter();
1616
public static final Block DATABASE = new BlockDatabase();

src/main/java/fr/bastoup/bperipherals/peripherals/cryprographicaccelerator/PeripheralCryptographicAccelerator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ public String getType() {
3737

3838
@Override
3939
public boolean equals(@Nullable IPeripheral other) {
40-
return other instanceof PeripheralCryptographicAccelerator && ((TileCryptographicAccelerator) other.getTarget()).getWorld().equals(tile.getWorld()) &&
41-
((TileCryptographicAccelerator) other.getTarget()).getPos().equals(tile.getPos());
40+
return this == other || other instanceof PeripheralCryptographicAccelerator && ((PeripheralCryptographicAccelerator) other).tile == tile;
4241
}
4342

4443
@LuaFunction
@@ -60,7 +59,7 @@ public final byte[] decodeBase64(String base64) throws LuaException {
6059
}
6160

6261
@LuaFunction
63-
public final String encodeBase64(ByteBuffer str) throws LuaException {
62+
public final String encodeBase64(ByteBuffer str) {
6463
byte[] strArray = Util.getByteBufferArray(str);
6564
return new String(Base64.getEncoder().encode(strArray));
6665
}

src/main/java/fr/bastoup/bperipherals/peripherals/database/BlockDatabase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected void fillStateContainer(StateContainer.Builder<Block, BlockState> buil
5656
super.fillStateContainer(builder);
5757
}
5858

59-
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
59+
public void onBlockPlacedBy(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, ItemStack stack) {
6060
if (stack.hasDisplayName()) {
6161
TileEntity tileentity = world.getTileEntity(pos);
6262
if (tileentity instanceof TileDatabase) {
@@ -67,7 +67,7 @@ public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, LivingE
6767
}
6868

6969
@Override
70-
public void harvestBlock(@Nonnull World world, PlayerEntity player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable TileEntity te, ItemStack stack) {
70+
public void harvestBlock(@Nonnull World world, @Nonnull PlayerEntity player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable TileEntity te, ItemStack stack) {
7171
if (te instanceof INameable && ((INameable) te).hasCustomName()) {
7272
player.addStat(Stats.BLOCK_MINED.get(this));
7373
player.addExhaustion(0.005F);

src/main/java/fr/bastoup/bperipherals/peripherals/database/ContainerDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public boolean canInteractWith(@Nonnull PlayerEntity player) {
4141
}
4242

4343
@Nonnull
44-
public ItemStack transferStackInSlot(PlayerEntity player, int slotIndex) {
44+
public ItemStack transferStackInSlot(@Nonnull PlayerEntity player, int slotIndex) {
4545
Slot slot = this.inventorySlots.get(slotIndex);
4646
if (slot != null && slot.getHasStack()) {
4747
ItemStack existing = slot.getStack().copy();

src/main/java/fr/bastoup/bperipherals/peripherals/database/GUIDatabase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public void render( @Nonnull MatrixStack transform, int mouseX, int mouseY, floa
2828
}
2929

3030
@Override
31-
protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int x, int y) {
32-
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
31+
protected void drawGuiContainerBackgroundLayer(@Nonnull MatrixStack matrixStack, float partialTicks, int x, int y) {
32+
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
3333
minecraft.getTextureManager().bindTexture(BACKGROUND);
3434
int i = (this.width - this.xSize) / 2;
3535
int j = (this.height - this.ySize) / 2;

src/main/java/fr/bastoup/bperipherals/peripherals/database/InventoryDatabase.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public Integer setDiskId(boolean force) {
2323
return null;
2424

2525
ItemStack item = super.stacks.get(0);
26-
if (item != null && item.getItem().equals(ModItems.DATABASE_DISK)) {
26+
if (item.getItem().equals(ModItems.DATABASE_DISK)) {
2727
CompoundNBT tag = item.getOrCreateTag();
2828
if (!force && tag.contains("databaseId")) {
2929
return null;
@@ -40,7 +40,7 @@ public Integer setDiskId(boolean force) {
4040

4141
public Integer getDiskId(boolean force) {
4242
ItemStack item = super.stacks.get(0);
43-
if (item != null && item.getItem().equals(ModItems.DATABASE_DISK)) {
43+
if (item.getItem().equals(ModItems.DATABASE_DISK)) {
4444
CompoundNBT tag = item.getTag();
4545
if (tag != null && tag.contains("databaseId")) {
4646
return tag.getInt("databaseId");
@@ -58,9 +58,9 @@ public Integer getDiskId(boolean force) {
5858

5959
public String getDiskName() {
6060
ItemStack item = super.stacks.get(0);
61-
if (item != null && item.getItem().equals(ModItems.DATABASE_DISK)) {
61+
if (item.getItem().equals(ModItems.DATABASE_DISK)) {
6262
CompoundNBT tag = item.getOrCreateTag();
63-
if (tag != null && tag.contains("databaseName")) {
63+
if (tag.contains("databaseName")) {
6464
return tag.getString("databaseName");
6565
}
6666
}
@@ -69,15 +69,15 @@ public String getDiskName() {
6969

7070
public void setDiskName(String name) {
7171
ItemStack item = super.stacks.get(0);
72-
if (item != null && item.getItem().equals(ModItems.DATABASE_DISK)) {
72+
if (item.getItem().equals(ModItems.DATABASE_DISK)) {
7373
CompoundNBT tag = item.getOrCreateTag();
7474
tag.putString("databaseName", name);
7575
}
7676
}
7777

7878
public boolean isDiskInserted() {
7979
ItemStack item = super.stacks.get(0);
80-
return item != null && item.getItem().equals(ModItems.DATABASE_DISK);
80+
return item.getItem().equals(ModItems.DATABASE_DISK);
8181
}
8282

8383
@Override

src/main/java/fr/bastoup/bperipherals/peripherals/database/PeripheralDatabase.java

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import fr.bastoup.bperipherals.database.DBUtil;
99
import fr.bastoup.bperipherals.util.peripherals.BPeripheral;
1010

11-
import java.io.File;
11+
import javax.annotation.Nonnull;
12+
import java.io.IOException;
13+
import java.nio.file.Path;
1214
import java.util.ArrayList;
1315
import java.util.HashMap;
1416
import java.util.List;
@@ -26,15 +28,15 @@ private TileDatabase getTile() {
2628
return ((TileDatabase) tile);
2729
}
2830

31+
@Nonnull
2932
@Override
3033
public String getType() {
3134
return TYPE;
3235
}
3336

3437
@Override
3538
public boolean equals(IPeripheral other) {
36-
return other instanceof PeripheralDatabase && ((TileDatabase) other.getTarget()).getWorld().equals(tile.getWorld()) &&
37-
((TileDatabase) other.getTarget()).getPos().equals(tile.getPos());
39+
return this == other || other instanceof PeripheralDatabase && ((PeripheralDatabase) other).tile == tile;
3840
}
3941

4042
@LuaFunction
@@ -65,19 +67,19 @@ public final void setDatabaseName(String name) throws LuaException {
6567

6668
@LuaFunction
6769
public final List<Object> executeSQL(String sql) throws LuaException {
68-
File file = null;
70+
Path file;
6971
try {
7072
file = getTile().getDatabaseFile();
71-
} catch (NoSuchFieldException e) {
72-
e.printStackTrace();
73-
} catch (IllegalAccessException e) {
73+
if (getTile().isDiskInserted()) {
74+
return DBUtil.factorizeResults(BPeripherals.getDBFactory().executeSQL(file.toString(), sql));
75+
} else {
76+
throw new LuaException("There is no disk inserted");
77+
}
78+
} catch (IllegalAccessException | IOException e) {
7479
e.printStackTrace();
80+
throw new LuaException("Internal Error. Please send an issue if the problem persists.");
7581
}
76-
if (getTile().isDiskInserted()) {
77-
return DBUtil.factorizeResults(BPeripherals.getDBFactory().executeSQL(file.getPath(), sql));
78-
} else {
79-
throw new LuaException("There is no disk inserted");
80-
}
82+
8183
}
8284

8385
@LuaFunction
@@ -136,7 +138,7 @@ public static class CCPreparedStatement {
136138

137139
private void peripheralStillValid() throws LuaException {
138140
TileDatabase t = (TileDatabase) database.getTarget();
139-
if (t.isRemoved())
141+
if (t == null || t.isRemoved())
140142
throw new LuaException("The peripheral does not exist.");
141143
}
142144

@@ -160,16 +162,19 @@ public final CCPreparedStatement removeParameter(int index) throws LuaException
160162
public final List<Object> execute() throws LuaException {
161163
peripheralStillValid();
162164
TileDatabase tile = (TileDatabase) database.getTarget();
163-
File file = null;
165+
Path file;
166+
167+
if (tile == null)
168+
throw new LuaException("Internal Error. Please send an issue if the problem persists.");
169+
164170
try {
165171
file = tile.getDatabaseFile();
166-
} catch (NoSuchFieldException e) {
167-
e.printStackTrace();
168-
} catch (IllegalAccessException e) {
172+
} catch (IllegalAccessException | IOException e) {
169173
e.printStackTrace();
174+
throw new LuaException("Internal Error. Please send an issue if the problem persists.");
170175
}
171176
if (tile.isDiskInserted()) {
172-
return DBUtil.factorizeResults(BPeripherals.getDBFactory().executePrepared(file.getPath(), this));
177+
return DBUtil.factorizeResults(BPeripherals.getDBFactory().executePrepared(file.toString(), this));
173178
} else {
174179
throw new LuaException("There is no disk inserted");
175180
}
@@ -198,7 +203,7 @@ public static class CCTableCreator {
198203

199204
private void peripheralStillValid() throws LuaException {
200205
TileDatabase t = (TileDatabase) database.getTarget();
201-
if (t.isRemoved())
206+
if (t == null || t.isRemoved())
202207
throw new LuaException("The peripheral does not exist.");
203208
}
204209

@@ -224,7 +229,7 @@ public final CCTableCreator addColumn(String name, String type, boolean notNull,
224229
}
225230

226231
@LuaFunction
227-
public final CCTableCreator removeColumn(String name) throws LuaException {
232+
public final CCTableCreator removeColumn(String name) {
228233
if (primaryKey.equalsIgnoreCase(name)) {
229234
primaryKey = null;
230235
autoIncrement = false;
@@ -253,13 +258,16 @@ public final CCTableCreator setPrimaryKey(String name, boolean autoIncrement) th
253258
public final List<Object> execute() throws LuaException {
254259
peripheralStillValid();
255260
TileDatabase tile = (TileDatabase) database.getTarget();
256-
File file = null;
261+
262+
if (tile == null)
263+
throw new LuaException("Internal Error. Please send an issue if the problem persists.");
264+
265+
Path file;
257266
try {
258267
file = tile.getDatabaseFile();
259-
} catch (NoSuchFieldException e) {
260-
e.printStackTrace();
261-
} catch (IllegalAccessException e) {
268+
} catch (IllegalAccessException | IOException e) {
262269
e.printStackTrace();
270+
throw new LuaException("Internal Error. Please send an issue if the problem persists.");
263271
}
264272
if (tile.isDiskInserted()) {
265273
if (this.primaryKey == null) {
@@ -281,7 +289,7 @@ public final List<Object> execute() throws LuaException {
281289
statements.add(statement);
282290
}
283291
String sql = "CREATE TABLE " + tableName + " (" + String.join(", ", statements) + ");";
284-
return DBUtil.factorizeResults(BPeripherals.getDBFactory().executeSQL(file.getPath(), sql));
292+
return DBUtil.factorizeResults(BPeripherals.getDBFactory().executeSQL(file.toString(), sql));
285293
} else {
286294
throw new LuaException("There is no disk inserted");
287295
}
@@ -300,18 +308,18 @@ public static class CCInsert {
300308

301309
private void peripheralStillValid() throws LuaException {
302310
TileDatabase t = (TileDatabase) database.getTarget();
303-
if (t.isRemoved())
311+
if (t == null || t.isRemoved())
304312
throw new LuaException("The peripheral does not exist.");
305313
}
306314

307315
@LuaFunction
308-
public final CCInsert addValue(String column, Object value) throws LuaException {
316+
public final CCInsert addValue(String column, Object value) {
309317
values.put(column.toLowerCase(), value);
310318
return this;
311319
}
312320

313321
@LuaFunction
314-
public final CCInsert removeValue(String column) throws LuaException {
322+
public final CCInsert removeValue(String column) {
315323
values.remove(column);
316324
return this;
317325
}
@@ -321,7 +329,7 @@ public final CCInsert removeValue(String column) throws LuaException {
321329
public final List<Object> execute() throws LuaException {
322330
peripheralStillValid();
323331
TileDatabase tile = (TileDatabase) database.getTarget();
324-
if (tile.isDiskInserted()) {
332+
if (tile != null && tile.isDiskInserted()) {
325333
List<String> s = new ArrayList<>();
326334
Map<Integer, Object> obj = new HashMap<>();
327335
Object[] keys = values.keySet().toArray();
@@ -351,18 +359,18 @@ public static class CCSelect {
351359

352360
private void peripheralStillValid() throws LuaException {
353361
TileDatabase t = (TileDatabase) database.getTarget();
354-
if (t.isRemoved())
362+
if (t == null || t.isRemoved())
355363
throw new LuaException("The peripheral does not exist.");
356364
}
357365

358366
@LuaFunction
359-
public final CCSelect addCondition(String column, Object value) throws LuaException {
367+
public final CCSelect addCondition(String column, Object value) {
360368
conditions.put(column.toLowerCase(), value);
361369
return this;
362370
}
363371

364372
@LuaFunction
365-
public final CCSelect removeCondition(String column) throws LuaException {
373+
public final CCSelect removeCondition(String column) {
366374
conditions.remove(column);
367375
return this;
368376
}
@@ -372,7 +380,7 @@ public final CCSelect removeCondition(String column) throws LuaException {
372380
public final List<Object> execute() throws LuaException {
373381
peripheralStillValid();
374382
TileDatabase tile = (TileDatabase) database.getTarget();
375-
if (tile.isDiskInserted()) {
383+
if (tile != null && tile.isDiskInserted()) {
376384
Map<Integer, Object> obj = new HashMap<>();
377385
List<String> k = new ArrayList<>();
378386
Object[] keys = conditions.keySet().toArray();
@@ -400,18 +408,18 @@ public static class CCDelete {
400408

401409
private void peripheralStillValid() throws LuaException {
402410
TileDatabase t = (TileDatabase) database.getTarget();
403-
if (t.isRemoved())
411+
if (t == null || t.isRemoved())
404412
throw new LuaException("The peripheral does not exist.");
405413
}
406414

407415
@LuaFunction
408-
public final CCDelete addCondition(String column, Object value) throws LuaException {
416+
public final CCDelete addCondition(String column, Object value) {
409417
conditions.put(column.toLowerCase(), value);
410418
return this;
411419
}
412420

413421
@LuaFunction
414-
public final CCDelete removeCondition(String column) throws LuaException {
422+
public final CCDelete removeCondition(String column) {
415423
conditions.remove(column);
416424
return this;
417425
}
@@ -421,7 +429,7 @@ public final CCDelete removeCondition(String column) throws LuaException {
421429
public final List<Object> execute() throws LuaException {
422430
peripheralStillValid();
423431
TileDatabase tile = (TileDatabase) database.getTarget();
424-
if (tile.isDiskInserted()) {
432+
if (tile != null && tile.isDiskInserted()) {
425433
Map<Integer, Object> obj = new HashMap<>();
426434
List<String> k = new ArrayList<>();
427435
Object[] keys = conditions.keySet().toArray();

0 commit comments

Comments
 (0)