Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
Also include LinkageError when logging
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBusyBiscuit committed Mar 24, 2021
1 parent 960365c commit 683a482
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 145 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.github.thebusybiscuit</groupId>
<artifactId>cscorelib2</artifactId>

<version>0.30.2</version>
<version>0.30.3</version>

<packaging>jar</packaging>
<url>https://github.com/TheBusyBiscuit/CS-CoreLib2</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class Config {
@Getter
private File file;

@Getter @Setter
@Getter
@Setter
private String header;

private Logger logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public int[] toPrimitive(@Nonnull UUID complex, @Nonnull PersistentDataAdapterCo
public UUID fromPrimitive(@Nonnull int[] primitive, @Nonnull PersistentDataAdapterContext context) {
return fromIntArray(primitive);
}

@Nonnull
public static UUID fromIntArray(@Nonnull int[] ints) {
Validate.notNull(ints, "The provided integer array cannot be null!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public static boolean isValidStackSize(@NonNull ItemStack stack, @NonNull ItemSt
*/
public static boolean isItemAllowed(@NonNull Material itemType, @NonNull InventoryType inventoryType) {
switch (inventoryType) {
case LECTERN:
// Lecterns only allow written books or writable books
return itemType == Material.WRITABLE_BOOK || itemType == Material.WRITTEN_BOOK;
case SHULKER_BOX:
// Shulker Boxes do not allow Shulker boxes
return itemType != Material.SHULKER_BOX && !itemType.name().endsWith("_SHULKER_BOX");
default:
return true;
case LECTERN:
// Lecterns only allow written books or writable books
return itemType == Material.WRITABLE_BOOK || itemType == Material.WRITTEN_BOOK;
case SHULKER_BOX:
// Shulker Boxes do not allow Shulker boxes
return itemType != Material.SHULKER_BOX && !itemType.name().endsWith("_SHULKER_BOX");
default:
return true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,20 @@ public static void consumeItem(@NonNull ItemStack item, int amount, boolean repl
if (item.getType() != Material.AIR && item.getAmount() > 0) {
if (replaceConsumables) {
switch (item.getType()) {
case POTION:
case DRAGON_BREATH:
case HONEY_BOTTLE:
item.setType(Material.GLASS_BOTTLE);
item.setAmount(1);
return;
case WATER_BUCKET:
case LAVA_BUCKET:
case MILK_BUCKET:
item.setType(Material.BUCKET);
item.setAmount(1);
return;
default:
break;
case POTION:
case DRAGON_BREATH:
case HONEY_BOTTLE:
item.setType(Material.GLASS_BOTTLE);
item.setAmount(1);
return;
case WATER_BUCKET:
case LAVA_BUCKET:
case MILK_BUCKET:
item.setType(Material.BUCKET);
item.setAmount(1);
return;
default:
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public boolean hasPermission(@NonNull OfflinePlayer p, @NonNull Location l, @Non
if (!module.hasPermission(p, l, action)) {
return false;
}
} catch (Exception x) {
} catch (Exception | LinkageError x) {
logger.log(Level.SEVERE, x, () -> "An Error occured while querying the Protection Module: \"" + module.getName() + " v" + module.getVersion() + "\"");
// Fallback will just be "allow".
return true;
Expand All @@ -195,7 +195,7 @@ public void logAction(@NonNull OfflinePlayer p, @NonNull Block b, @NonNull Prote
for (ProtectionLogger module : protectionLoggers) {
try {
module.logAction(p, b, action);
} catch (Exception x) {
} catch (Exception | LinkageError x) {
logger.log(Level.SEVERE, x, () -> "An Error occured while logging for the Protection Module: \"" + module.getName() + "\"");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ public String getName() {
@Override
public void logAction(OfflinePlayer p, Block b, ProtectableAction action) {
switch (action) {
case INTERACT_BLOCK:
coreprotect.logContainerTransaction(p.getName(), b.getLocation());
break;
case BREAK_BLOCK:
coreprotect.logRemoval(p.getName(), b.getLocation(), b.getType(), b.getBlockData());
break;
case PLACE_BLOCK:
coreprotect.logPlacement(p.getName(), b.getLocation(), b.getType(), b.getBlockData());
break;
default:
break;
case INTERACT_BLOCK:
coreprotect.logContainerTransaction(p.getName(), b.getLocation());
break;
case BREAK_BLOCK:
coreprotect.logRemoval(p.getName(), b.getLocation(), b.getType(), b.getBlockData());
break;
case PLACE_BLOCK:
coreprotect.logPlacement(p.getName(), b.getLocation(), b.getType(), b.getBlockData());
break;
default:
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,23 @@ public boolean hasPermission(OfflinePlayer p, Location l, ProtectableAction acti

private Flag convert(ProtectableAction action, World world) {
switch (action) {
case INTERACT_BLOCK:
return Flags.CONTAINER;
case ATTACK_PLAYER:
if (world.getEnvironment() == World.Environment.NETHER) {
return Flags.PVP_NETHER;
} else if (world.getEnvironment() == World.Environment.THE_END) {
return Flags.PVP_END;
} else {
return Flags.PVP_OVERWORLD;
}
case BREAK_BLOCK:
return Flags.BREAK_BLOCKS;
case ATTACK_ENTITY:
return Flags.HURT_ANIMALS;
case PLACE_BLOCK:
default:
return Flags.PLACE_BLOCKS;
case INTERACT_BLOCK:
return Flags.CONTAINER;
case ATTACK_PLAYER:
if (world.getEnvironment() == World.Environment.NETHER) {
return Flags.PVP_NETHER;
} else if (world.getEnvironment() == World.Environment.THE_END) {
return Flags.PVP_END;
} else {
return Flags.PVP_OVERWORLD;
}
case BREAK_BLOCK:
return Flags.BREAK_BLOCKS;
case ATTACK_ENTITY:
return Flags.HURT_ANIMALS;
case PLACE_BLOCK:
default:
return Flags.PLACE_BLOCKS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ public boolean hasPermission(OfflinePlayer p, Location l, ProtectableAction acti
}

switch (action) {
case INTERACT_BLOCK:
return claim.allowContainers((Player) p) == null;
case ATTACK_PLAYER:
return claim.siegeData == null || claim.siegeData.attacker == null;
case BREAK_BLOCK:
return claim.allowBreak((Player) p, l.getBlock().getType()) == null;
case PLACE_BLOCK:
return claim.allowBuild((Player) p, l.getBlock().getType()) == null;
default:
return claim.allowAccess((Player) p) == null;
case INTERACT_BLOCK:
return claim.allowContainers((Player) p) == null;
case ATTACK_PLAYER:
return claim.siegeData == null || claim.siegeData.attacker == null;
case BREAK_BLOCK:
return claim.allowBreak((Player) p, l.getBlock().getType()) == null;
case PLACE_BLOCK:
return claim.allowBuild((Player) p, l.getBlock().getType()) == null;
default:
return claim.allowAccess((Player) p) == null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ public boolean hasPermission(OfflinePlayer p, Location l, ProtectableAction acti

private RoleSetting convert(ProtectableAction protectableAction) {
switch (protectableAction) {
case PLACE_BLOCK:
return RoleSetting.BLOCK_PLACE;
case BREAK_BLOCK:
return RoleSetting.BLOCK_BREAK;
case ATTACK_PLAYER:
return RoleSetting.ATTACK_PLAYER;
case INTERACT_BLOCK:
return RoleSetting.INTERACT_CONTAINER;
case INTERACT_ENTITY:
return RoleSetting.INTERACT_VILLAGER;
case ATTACK_ENTITY:
return RoleSetting.ATTACK_ANIMAL;
default:
return RoleSetting.BLOCK_BREAK;
case PLACE_BLOCK:
return RoleSetting.BLOCK_PLACE;
case BREAK_BLOCK:
return RoleSetting.BLOCK_BREAK;
case ATTACK_PLAYER:
return RoleSetting.ATTACK_PLAYER;
case INTERACT_BLOCK:
return RoleSetting.INTERACT_CONTAINER;
case INTERACT_ENTITY:
return RoleSetting.INTERACT_VILLAGER;
case ATTACK_ENTITY:
return RoleSetting.ATTACK_ANIMAL;
default:
return RoleSetting.BLOCK_BREAK;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ public boolean hasPermission(OfflinePlayer p, org.bukkit.Location l, Protectable

private boolean check(OfflinePlayer p, ProtectableAction action) {
switch (action) {
case INTERACT_BLOCK:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.PERMISSION_ADMIN_INTERACT_UNOWNED);
case INTERACT_ENTITY:
case ATTACK_ENTITY:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.FLAG_ANIMAL_INTERACT);
case ATTACK_PLAYER:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.FLAG_PVP);
case PLACE_BLOCK:
default:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.PERMISSION_ADMIN_BUILD_UNOWNED);
case INTERACT_BLOCK:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.PERMISSION_ADMIN_INTERACT_UNOWNED);
case INTERACT_ENTITY:
case ATTACK_ENTITY:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.FLAG_ANIMAL_INTERACT);
case ATTACK_PLAYER:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.FLAG_PVP);
case PLACE_BLOCK:
default:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.PERMISSION_ADMIN_BUILD_UNOWNED);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ public boolean hasPermission(OfflinePlayer p, org.bukkit.Location l, Protectable

private boolean check(OfflinePlayer p, ProtectableAction action) {
switch (action) {
case INTERACT_BLOCK:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.PERMISSION_ADMIN_INTERACT_UNOWNED);
case INTERACT_ENTITY:
case ATTACK_ENTITY:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.FLAG_ANIMAL_INTERACT);
case ATTACK_PLAYER:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.FLAG_PVP);
case PLACE_BLOCK:
default:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.PERMISSION_ADMIN_BUILD_UNOWNED);
case INTERACT_BLOCK:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.PERMISSION_ADMIN_INTERACT_UNOWNED);
case INTERACT_ENTITY:
case ATTACK_ENTITY:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.FLAG_ANIMAL_INTERACT);
case ATTACK_PLAYER:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.FLAG_PVP);
case PLACE_BLOCK:
default:
return Permissions.hasPermission(PlotPlayer.wrap(p), Captions.PERMISSION_ADMIN_BUILD_UNOWNED);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ public boolean hasPermission(OfflinePlayer p, Location l, ProtectableAction acti
}

switch (action) {
case ATTACK_PLAYER:
return !api.flagAppliesToPlayer((Player) p, FieldFlag.PREVENT_PVP, l);
case INTERACT_ENTITY:
case ATTACK_ENTITY:
return !api.flagAppliesToPlayer((Player) p, FieldFlag.PREVENT_ENTITY_INTERACT, l);
case BREAK_BLOCK:
return api.canBreak((Player) p, l);
case INTERACT_BLOCK:
case PLACE_BLOCK:
return api.canPlace((Player) p, l);
default:
return false;
case ATTACK_PLAYER:
return !api.flagAppliesToPlayer((Player) p, FieldFlag.PREVENT_PVP, l);
case INTERACT_ENTITY:
case ATTACK_ENTITY:
return !api.flagAppliesToPlayer((Player) p, FieldFlag.PREVENT_ENTITY_INTERACT, l);
case BREAK_BLOCK:
return api.canBreak((Player) p, l);
case INTERACT_BLOCK:
case PLACE_BLOCK:
return api.canPlace((Player) p, l);
default:
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ public boolean hasPermission(OfflinePlayer p, Location l, ProtectableAction acti

Player player = (Player) p;
switch (action) {
case INTERACT_BLOCK:
return region.canChest(player);
case ATTACK_ENTITY:
case INTERACT_ENTITY:
return region.canInteractPassives(player);
case ATTACK_PLAYER:
return region.canPVP(player, player);
case BREAK_BLOCK:
case PLACE_BLOCK:
default:
return region.canBuild(player);
case INTERACT_BLOCK:
return region.canChest(player);
case ATTACK_ENTITY:
case INTERACT_ENTITY:
return region.canInteractPassives(player);
case ATTACK_PLAYER:
return region.canPVP(player, player);
case BREAK_BLOCK:
case PLACE_BLOCK:
default:
return region.canBuild(player);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ public boolean hasPermission(OfflinePlayer p, Location l, ProtectableAction acti

private ActionType convert(ProtectableAction action) {
switch (action) {
case INTERACT_BLOCK:
case INTERACT_ENTITY:
case ATTACK_PLAYER:
case ATTACK_ENTITY:
return ActionType.ITEM_USE;
case BREAK_BLOCK:
return ActionType.DESTROY;
case PLACE_BLOCK:
default:
return ActionType.BUILD;
case INTERACT_BLOCK:
case INTERACT_ENTITY:
case ATTACK_PLAYER:
case ATTACK_ENTITY:
return ActionType.ITEM_USE;
case BREAK_BLOCK:
return ActionType.DESTROY;
case PLACE_BLOCK:
default:
return ActionType.BUILD;
}
}

Expand Down
Loading

0 comments on commit 683a482

Please sign in to comment.