Skip to content

Commit

Permalink
fixed bug which broke backwards compatibility, added exception wrappe…
Browse files Browse the repository at this point in the history
…r for more useful debugging
  • Loading branch information
drew6017 committed Jun 28, 2021
1 parent 8708e41 commit 8bdd12b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/divisionind/bprm/nms/reflect/NMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.divisionind.bprm.FakeBackpackViewer;
import com.divisionind.bprm.nms.KnownVersion;
import com.divisionind.bprm.nms.reflect.ex.NMSLoadException;
import org.bukkit.Bukkit;
import org.bukkit.entity.HumanEntity;

Expand Down Expand Up @@ -49,7 +50,7 @@ public static List<Exception> initialize() {
try {
nmsClass.init();
} catch (Exception e) {
exceptions.add(e);
exceptions.add(new NMSLoadException("NMSClass: " + nmsClass.name(), e));
}
}

Expand All @@ -62,7 +63,7 @@ public static List<Exception> initialize() {
try {
type.init(NMSClass.NBTTagCompound.getClazz());
} catch (Exception e) {
exceptions.add(e);
exceptions.add(new NMSLoadException("NMSType: " + type.name(), e));
}
}

Expand All @@ -71,7 +72,7 @@ public static List<Exception> initialize() {
try {
nmsMethod.init();
} catch (Exception e) {
exceptions.add(e);
exceptions.add(new NMSLoadException("NMSMethod: " + nmsMethod.name(), e));
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/main/java/com/divisionind/bprm/nms/reflect/NMSMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ public enum NMSMethod {
//load(TileEntityFurnace, "load", NBTTagCompound.getClazz()),
getInventory(CraftInventory, "getInventory"),
getBukkitEntity(EntityPlayer, "getBukkitEntity"),
getWorld(() -> KnownVersion.v1_17_R1.isBefore() ? null : TileEntity.getClazz().getMethod("getWorld")),
getPosition(() -> KnownVersion.v1_17_R1.isBefore() ? null : TileEntity.getClazz().getMethod("getPosition")),
getBlock(() -> KnownVersion.v1_17_R1.isBefore() ? null : TileEntity.getClazz().getMethod("getBlock")),
getTileEntity(CraftTileInventoryConverter_Furnace, "getTileEntity");
getWorld(() -> KnownVersion.v1_17_R1.isBefore() ? null : TileEntity.getClazz().getMethod("getWorld")),
getPosition(() -> KnownVersion.v1_17_R1.isBefore() ? null : TileEntity.getClazz().getMethod("getPosition")),
getBlock(() -> KnownVersion.v1_17_R1.isBefore() ? null : TileEntity.getClazz().getMethod("getBlock")),
getTileEntity(() -> KnownVersion.v1_17_R1.isBefore() ? null : CraftTileInventoryConverter_Furnace
.getClazz().getMethod("getTileEntity"));

private Method method;
private MethodInitializer methodInitializer;
Expand All @@ -89,7 +90,10 @@ public enum NMSMethod {

void init() throws NoSuchMethodException {
this.method = methodInitializer.init();
if (methodPrivate) this.method.setAccessible(true);

if (methodPrivate)
this.method.setAccessible(true);

this.methodInitializer = null; // so the initializer can be garbage collected, we will never need it again
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* BackpacksRemastered - remastered version of the popular Backpacks plugin
* Copyright (C) 2019 - 2020, Andrew Howard, <divisionind.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.divisionind.bprm.nms.reflect.ex;

public class NMSLoadException extends Exception {
public NMSLoadException() {
}

public NMSLoadException(String message) {
super(message);
}

public NMSLoadException(String message, Throwable cause) {
super(message, cause);
}

public NMSLoadException(Throwable cause) {
super(cause);
}
}

0 comments on commit 8bdd12b

Please sign in to comment.