From 73f9df9ccec3a3ed0235ff8175b67240fa5b2790 Mon Sep 17 00:00:00 2001
From: Pietje
Date: Thu, 3 Mar 2016 15:46:14 +0100
Subject: [PATCH] Moved player_event modify format check.
Bukkits ..Event.setFormat(String format) throws an exception when the
format is invalid. CH now catches that exception and attemts to give a
more user friendly exception back to the user.
---
.../core/events/drivers/PlayerEvents.java | 21 ++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/src/main/java/com/laytonsmith/core/events/drivers/PlayerEvents.java b/src/main/java/com/laytonsmith/core/events/drivers/PlayerEvents.java
index 1193868f5..5423113d7 100644
--- a/src/main/java/com/laytonsmith/core/events/drivers/PlayerEvents.java
+++ b/src/main/java/com/laytonsmith/core/events/drivers/PlayerEvents.java
@@ -1542,18 +1542,25 @@ public boolean modifyEvent(String key, Construct value, BindableEvent event) {
if("format".equals(key)){
String format = value.nval();
if(format == null) {
- throw new CRENullPointerException("The \"format\" key in " + modify_event.class.getSimpleName() + " for the " + this.getName()
+ throw new CRENullPointerException("The \"format\" key in " + new modify_event().getName() + " for the " + this.getName()
+ " event may not be null.", Target.UNKNOWN);
- } else if(format.replaceAll("%%", "").replaceAll("\\%\\%|\\%[12]\\$s", "").contains("%")) {
- throw new CREFormatException("The \"format\" key in " + modify_event.class.getSimpleName() + " for the " + this.getName()
- + " event only accepts %1$s and %1$s as format specifiers. Use a \"%%\" to display a single \"%\".", Target.UNKNOWN);
}
try{
- e.setFormat(format);
- } catch(UnknownFormatConversionException | IllegalFormatConversionException | FormatFlagsConversionMismatchException ex){
- throw new CREFormatException(ex.getMessage(), Target.UNKNOWN);
+ // Throws UnknownFormatConversionException, MissingFormatException,
+ // IllegalFormatConversionException, FormatFlagsConversionMismatchException, NullPointerException and possibly more.
+ e.setFormat(format);
+ } catch(Exception ex){
+ // Check the format to give a better exception message.
+ if(format.replaceAll("%%", "").replaceAll("\\%\\%|\\%[12]\\$s", "").contains("%")) {
+ throw new CREFormatException("The \"format\" key in " + modify_event.class.getSimpleName() + " for the " + this.getName()
+ + " event only accepts %1$s and %2$s as format specifiers. Use a \"%%\" to display a single \"%\".", Target.UNKNOWN);
+ } else {
+ throw new CREFormatException("The \"format\" key in " + modify_event.class.getSimpleName() + " for the " + this.getName()
+ + " event was set to an invalid value: " + format + ". The original exception message is: " + ex.getMessage(), Target.UNKNOWN);
+ }
}
}
+
return true;
}
return false;