Skip to content

Commit

Permalink
updated sentry error reporting system + 4.3.0 release version!
Browse files Browse the repository at this point in the history
  • Loading branch information
RoboTricker committed Jan 28, 2018
1 parent ae3c6d0 commit 28d0a14
Show file tree
Hide file tree
Showing 13 changed files with 619 additions and 495 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry</artifactId>
<version>1.6.3</version>
<version>1.6.5</version>
<scope>compile</scope>
</dependency>
<!--<dependency> <groupId>org.bstats</groupId> <artifactId>bstats-bukkit</artifactId>
Expand Down
83 changes: 42 additions & 41 deletions src/main/java/de/robotricker/transportpipes/TransportPipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,17 @@ public class TransportPipes extends JavaPlugin {
@Override
public void onEnable() {
instance = this;

Sentry.init("https://2eb0fc30f86a4871a85755ecdde11679:26f44195e9ef47f38e99051f7d15594f@sentry.io/252970?stacktrace.app.packages=de.robotricker");
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

@Override
public void uncaughtException(Thread t, Throwable e) {
Sentry.capture(e);
}
});
initSentryOnCurrentThread();

DuctType.PIPE.setDuctDetailsClass(PipeDetails.class);
DuctType.PIPE.setTickRunnable(new TickRunnable() {

Expand Down Expand Up @@ -365,40 +374,44 @@ public UpdateUtils getUpdateManager() {

@Override
public void onDisable() {
pipeThread.setRunning(false);
try {
pipeThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
savingManager.saveDuctsSync(true);

// despawn all pipes and items
Map<World, Map<BlockLoc, Duct>> fullDuctMap = getFullDuctMap();
synchronized (fullDuctMap) {
for (Map<BlockLoc, Duct> ductMap : fullDuctMap.values()) {
for (Duct duct : ductMap.values()) {

ductManager.destroyDuct(duct);

if (duct instanceof Pipe) {
Pipe pipe = (Pipe) duct;
Collection<PipeItem> allItems = new ArrayList<>();
synchronized (pipe.pipeItems) {
allItems.addAll(pipe.pipeItems.keySet());
}
synchronized (pipe.tempPipeItems) {
allItems.addAll(pipe.tempPipeItems.keySet());
}
synchronized (pipe.tempPipeItemsWithSpawn) {
allItems.addAll(pipe.tempPipeItemsWithSpawn.keySet());
}
for (PipeItem pi : allItems) {
ductManager.destroyPipeItem(pi);
pipeThread.setRunning(false);
try {
pipeThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
savingManager.saveDuctsSync(true);
// despawn all pipes and items
Map<World, Map<BlockLoc, Duct>> fullDuctMap = getFullDuctMap();
synchronized (fullDuctMap) {
for (Map<BlockLoc, Duct> ductMap : fullDuctMap.values()) {
for (Duct duct : ductMap.values()) {

ductManager.destroyDuct(duct);

if (duct instanceof Pipe) {
Pipe pipe = (Pipe) duct;
Collection<PipeItem> allItems = new ArrayList<>();
synchronized (pipe.pipeItems) {
allItems.addAll(pipe.pipeItems.keySet());
}
synchronized (pipe.tempPipeItems) {
allItems.addAll(pipe.tempPipeItems.keySet());
}
synchronized (pipe.tempPipeItemsWithSpawn) {
allItems.addAll(pipe.tempPipeItemsWithSpawn.keySet());
}
for (PipeItem pi : allItems) {
ductManager.destroyPipeItem(pi);
}
}
}
}
}
} catch (Exception exception) {
exception.printStackTrace();
Sentry.capture(exception);
}

}
Expand Down Expand Up @@ -438,20 +451,8 @@ public static boolean isBlockProtectedByLWC(Block b) {
}

public static void initSentryOnCurrentThread() {

Sentry.init("https://2eb0fc30f86a4871a85755ecdde11679:26f44195e9ef47f38e99051f7d15594f@sentry.io/252970");
Sentry.getContext().setUser(new UserBuilder().setUsername("RoboTricker").build());
Sentry.getContext().addTag("thread", Thread.currentThread().getName());
Sentry.getContext().addTag("version", TransportPipes.instance.getDescription().getVersion());

Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

@Override
public void uncaughtException(Thread t, Throwable e) {
Sentry.capture(e);
}
});

}

}
83 changes: 47 additions & 36 deletions src/main/java/de/robotricker/transportpipes/api/PipeAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import de.robotricker.transportpipes.utils.WrappedDirection;
import de.robotricker.transportpipes.utils.ductdetails.PipeDetails;
import de.robotricker.transportpipes.utils.staticutils.DuctUtils;
import io.sentry.Sentry;

/**
*
Expand Down Expand Up @@ -105,7 +106,7 @@ public static int getDuctCount(World world) {
*/
public static boolean isDuct(Location blockLoc, DuctType dt) {
Duct duct = DuctUtils.getDuctAtLocation(blockLoc);
if(dt == null) {
if (dt == null) {
return duct != null;
}
return duct != null && duct.getDuctType() == dt;
Expand Down Expand Up @@ -173,23 +174,28 @@ public static void registerTransportPipesContainer(Location blockLoc, TransportP
}
containerMap.put(bl, tpc);

Map<BlockLoc, Duct> ductMap = TransportPipes.instance.getDuctMap(blockLoc.getWorld());
if (ductMap != null) {
for (WrappedDirection pd : WrappedDirection.values()) {
bl = BlockLoc.convertBlockLoc(blockLoc.clone().add(pd.getX(), pd.getY(), pd.getZ()));
if (ductMap.containsKey(bl)) {
final Duct duct = ductMap.get(bl);
if (duct.getDuctType() == DuctType.PIPE) {
TransportPipes.instance.pipeThread.runTask(new Runnable() {

@Override
public void run() {
TransportPipes.instance.ductManager.updateDuct((Pipe) duct);
}
}, 0);
try {
Map<BlockLoc, Duct> ductMap = TransportPipes.instance.getDuctMap(blockLoc.getWorld());
if (ductMap != null) {
for (WrappedDirection pd : WrappedDirection.values()) {
bl = BlockLoc.convertBlockLoc(blockLoc.clone().add(pd.getX(), pd.getY(), pd.getZ()));
if (ductMap.containsKey(bl)) {
final Duct duct = ductMap.get(bl);
if (duct.getDuctType() == DuctType.PIPE) {
TransportPipes.instance.pipeThread.runTask(new Runnable() {

@Override
public void run() {
TransportPipes.instance.ductManager.updateDuct((Pipe) duct);
}
}, 0);
}
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
Sentry.capture(ex);
}

}
Expand All @@ -199,32 +205,37 @@ public void run() {
* {@link PipeAPI#registerTransportPipesContainer(Location, TransportPipesContainer)}
*/
public static void unregisterTransportPipesContainer(Location blockLoc) {
BlockLoc bl = BlockLoc.convertBlockLoc(blockLoc);

Map<BlockLoc, TransportPipesContainer> containerMap = TransportPipes.instance.getContainerMap(blockLoc.getWorld());
if (containerMap != null) {
if (containerMap.containsKey(bl)) {
containerMap.remove(bl);

Map<BlockLoc, Duct> ductMap = TransportPipes.instance.getDuctMap(blockLoc.getWorld());
if (ductMap != null) {
for (WrappedDirection pd : WrappedDirection.values()) {
bl = BlockLoc.convertBlockLoc(blockLoc.clone().add(pd.getX(), pd.getY(), pd.getZ()));
if (ductMap.containsKey(bl)) {
final Duct duct = ductMap.get(bl);
if (duct.getDuctType() == DuctType.PIPE) {
TransportPipes.instance.pipeThread.runTask(new Runnable() {

@Override
public void run() {
TransportPipes.instance.ductManager.updateDuct((Pipe) duct);
}
}, 0);
try {
BlockLoc bl = BlockLoc.convertBlockLoc(blockLoc);

Map<BlockLoc, TransportPipesContainer> containerMap = TransportPipes.instance.getContainerMap(blockLoc.getWorld());
if (containerMap != null) {
if (containerMap.containsKey(bl)) {
containerMap.remove(bl);

Map<BlockLoc, Duct> ductMap = TransportPipes.instance.getDuctMap(blockLoc.getWorld());
if (ductMap != null) {
for (WrappedDirection pd : WrappedDirection.values()) {
bl = BlockLoc.convertBlockLoc(blockLoc.clone().add(pd.getX(), pd.getY(), pd.getZ()));
if (ductMap.containsKey(bl)) {
final Duct duct = ductMap.get(bl);
if (duct.getDuctType() == DuctType.PIPE) {
TransportPipes.instance.pipeThread.runTask(new Runnable() {

@Override
public void run() {
TransportPipes.instance.ductManager.updateDuct((Pipe) duct);
}
}, 0);
}
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
Sentry.capture(e);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.bukkit.inventory.ItemStack;

import de.robotricker.transportpipes.api.TransportPipesContainer;
import io.sentry.Sentry;

public abstract class BlockContainer implements TransportPipesContainer {

Expand All @@ -31,50 +32,66 @@ public BlockContainer(Block block) {
* if the item couldn't be inserted, the result item is equal to {@link before}.
*/
protected ItemStack putItemInSlot(ItemStack toPut, ItemStack before) {
if (toPut == null) {
return before;
}
if (before == null) {
ItemStack returnCopy = toPut.clone();
toPut.setAmount(0);
return returnCopy;
}
ItemStack beforeItemStack = before.clone();
if (beforeItemStack.isSimilar(toPut)) {
int beforeAmount = beforeItemStack.getAmount();
beforeItemStack.setAmount(Math.min(before.getMaxStackSize(), beforeAmount + toPut.getAmount()));
toPut.setAmount(Math.max(0, toPut.getAmount() - (before.getMaxStackSize() - beforeAmount)));
try {
if (toPut == null) {
return before;
}
if (before == null) {
ItemStack returnCopy = toPut.clone();
toPut.setAmount(0);
return returnCopy;
}
ItemStack beforeItemStack = before.clone();
if (beforeItemStack.isSimilar(toPut)) {
int beforeAmount = beforeItemStack.getAmount();
beforeItemStack.setAmount(Math.min(before.getMaxStackSize(), beforeAmount + toPut.getAmount()));
toPut.setAmount(Math.max(0, toPut.getAmount() - (before.getMaxStackSize() - beforeAmount)));
}
return beforeItemStack;
} catch (Exception e) {
e.printStackTrace();
Sentry.capture(e);
}
return beforeItemStack;
return null;
}

protected int howManyItemsFit(ItemStack toPut, ItemStack before) {
if (toPut == null) {
return 0;
}
if (before == null) {
return toPut.getMaxStackSize();
}
if (before.isSimilar(toPut)) {
if (before.getAmount() < before.getMaxStackSize()) {
return before.getMaxStackSize() - before.getAmount();
try {
if (toPut == null) {
return 0;
}
if (before == null) {
return toPut.getMaxStackSize();
}
if (before.isSimilar(toPut)) {
if (before.getAmount() < before.getMaxStackSize()) {
return before.getMaxStackSize() - before.getAmount();
} else {
return 0;
}
} else {
return 0;
}
} else {
return 0;
} catch (Exception e) {
e.printStackTrace();
Sentry.capture(e);
}
return 0;
}

protected boolean isInvLocked(InventoryHolder ih) {
// check vanilla lock
if (vanillaLockableExists && ih instanceof org.bukkit.block.Lockable) {
if (((org.bukkit.block.Lockable) ih).isLocked()) {
return true;
try {
// check vanilla lock
if (vanillaLockableExists && ih instanceof org.bukkit.block.Lockable) {
if (((org.bukkit.block.Lockable) ih).isLocked()) {
return true;
}
}
} catch (Exception e) {
e.printStackTrace();
Sentry.capture(e);
}
return false;

}

public abstract void updateBlock();
Expand Down
Loading

0 comments on commit 28d0a14

Please sign in to comment.