Migrate some users of FilePrinter to slf4j.Logger
At least we got rid of one printError method
This commit is contained in:
@@ -22,11 +22,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package scripting.reactor;
|
||||
|
||||
import client.Client;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import scripting.AbstractScriptManager;
|
||||
import server.maps.Reactor;
|
||||
import server.maps.ReactorDropEntry;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.FilePrinter;
|
||||
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
@@ -43,6 +44,7 @@ import java.util.Map;
|
||||
* @author Lerk
|
||||
*/
|
||||
public class ReactorScriptManager extends AbstractScriptManager {
|
||||
private static final Logger log = LoggerFactory.getLogger(ReactorScriptManager.class);
|
||||
private static final ReactorScriptManager instance = new ReactorScriptManager();
|
||||
|
||||
private final Map<Integer, List<ReactorDropEntry>> drops = new HashMap<>();
|
||||
@@ -60,10 +62,9 @@ public class ReactorScriptManager extends AbstractScriptManager {
|
||||
|
||||
iv.invokeFunction("hit");
|
||||
} catch (final NoSuchMethodException e) {
|
||||
} //do nothing, hit is OPTIONAL
|
||||
|
||||
catch (final ScriptException | NullPointerException e) {
|
||||
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", e);
|
||||
//do nothing, hit is OPTIONAL
|
||||
} catch (final ScriptException | NullPointerException e) {
|
||||
log.error("Error during onHit script for reactor: {}", reactor.getId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,17 +77,17 @@ public class ReactorScriptManager extends AbstractScriptManager {
|
||||
|
||||
iv.invokeFunction("act");
|
||||
} catch (final ScriptException | NoSuchMethodException | NullPointerException e) {
|
||||
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", e);
|
||||
log.error("Error during act script for reactor: {}", reactor.getId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ReactorDropEntry> getDrops(int rid) {
|
||||
List<ReactorDropEntry> ret = drops.get(rid);
|
||||
public List<ReactorDropEntry> getDrops(int reactorId) {
|
||||
List<ReactorDropEntry> ret = drops.get(reactorId);
|
||||
if (ret == null) {
|
||||
ret = new LinkedList<>();
|
||||
try (Connection con = DatabaseConnection.getConnection()) {
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT itemid, chance, questid FROM reactordrops WHERE reactorid = ? AND chance >= 0")) {
|
||||
ps.setInt(1, rid);
|
||||
ps.setInt(1, reactorId);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
ret.add(new ReactorDropEntry(rs.getInt("itemid"), rs.getInt("chance"), rs.getInt("questid")));
|
||||
@@ -94,9 +95,9 @@ public class ReactorScriptManager extends AbstractScriptManager {
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
FilePrinter.printError(FilePrinter.REACTOR + rid + ".txt", e);
|
||||
log.error("Error getting drops for reactor: {}", reactorId);
|
||||
}
|
||||
drops.put(rid, ret);
|
||||
drops.put(reactorId, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -114,19 +115,16 @@ public class ReactorScriptManager extends AbstractScriptManager {
|
||||
}
|
||||
|
||||
private void touching(Client c, Reactor reactor, boolean touching) {
|
||||
final String functionName = touching ? "touch" : "untouch";
|
||||
try {
|
||||
Invocable iv = initializeInvocable(c, reactor);
|
||||
if (iv == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (touching) {
|
||||
iv.invokeFunction("touch");
|
||||
} else {
|
||||
iv.invokeFunction("untouch");
|
||||
}
|
||||
} catch (final ScriptException | NoSuchMethodException | NullPointerException ute) {
|
||||
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", ute);
|
||||
iv.invokeFunction(functionName);
|
||||
} catch (final ScriptException | NoSuchMethodException | NullPointerException e) {
|
||||
log.error("Error during {} script for reactor: {}", functionName, reactor.getId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user