Migrate some users of FilePrinter to slf4j.Logger

At least we got rid of one printError method
This commit is contained in:
P0nk
2022-01-19 18:36:19 +01:00
parent 0b66766e8a
commit 53465bba25
8 changed files with 47 additions and 80 deletions

View File

@@ -23,8 +23,9 @@ package scripting.map;
import client.Character;
import client.Client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scripting.AbstractScriptManager;
import tools.FilePrinter;
import javax.script.Invocable;
import javax.script.ScriptException;
@@ -32,6 +33,7 @@ import java.util.HashMap;
import java.util.Map;
public class MapScriptManager extends AbstractScriptManager {
private static final Logger log = LoggerFactory.getLogger(MapScriptManager.class);
private static final MapScriptManager instance = new MapScriptManager();
private final Map<String, Invocable> scripts = new HashMap<>();
@@ -75,7 +77,7 @@ public class MapScriptManager extends AbstractScriptManager {
iv.invokeFunction("start", new MapScriptMethods(c));
return true;
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.MAP_SCRIPT + mapScriptPath + ".txt", e);
log.error("Error running map script {}", mapScriptPath, e);
}
return false;

View File

@@ -24,9 +24,10 @@ package scripting.npc;
import client.Character;
import client.Client;
import net.server.world.PartyCharacter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scripting.AbstractScriptManager;
import server.ItemInformationProvider.ScriptedItem;
import tools.FilePrinter;
import tools.PacketCreator;
import javax.script.Invocable;
@@ -40,6 +41,7 @@ import java.util.Map;
* @author Matze
*/
public class NPCScriptManager extends AbstractScriptManager {
private static final Logger log = LoggerFactory.getLogger(NPCScriptManager.class);
private static final NPCScriptManager instance = new NPCScriptManager();
private final Map<Client, NPCConversationManager> cms = new HashMap<>();
@@ -104,7 +106,7 @@ public class NPCScriptManager extends AbstractScriptManager {
}
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.NPC + npc + ".txt", e);
log.error("Error starting NPC script: {}", npc, e);
dispose(c);
}
}
@@ -154,7 +156,7 @@ public class NPCScriptManager extends AbstractScriptManager {
}
return true;
} catch (final Exception ute) {
FilePrinter.printError(FilePrinter.NPC + npc + ".txt", ute);
log.error("Error starting NPC script: {}", npc);
dispose(c);
return false;
@@ -169,7 +171,7 @@ public class NPCScriptManager extends AbstractScriptManager {
iv.invokeFunction("action", mode, type, selection);
} catch (ScriptException | NoSuchMethodException t) {
if (getCM(c) != null) {
FilePrinter.printError(FilePrinter.NPC + getCM(c).getNpc() + ".txt", t);
log.error("Error performing NPC script action for npc: {}", getCM(c).getNpc(), t);
}
dispose(c);
}

View File

@@ -24,13 +24,14 @@ package scripting.quest;
import client.Client;
import client.QuestStatus;
import constants.game.GameConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scripting.AbstractScriptManager;
import server.quest.Quest;
import tools.FilePrinter;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.HashMap;
import java.util.Map;
@@ -38,6 +39,7 @@ import java.util.Map;
* @author RMZero213
*/
public class QuestScriptManager extends AbstractScriptManager {
private static final Logger log = LoggerFactory.getLogger(QuestScriptManager.class);
private static final QuestScriptManager instance = new QuestScriptManager();
private final Map<Client, QuestActionManager> qms = new HashMap<>();
@@ -85,11 +87,8 @@ public class QuestScriptManager extends AbstractScriptManager {
c.setClickedNPC();
iv.invokeFunction("start", (byte) 1, (byte) 0, 0);
}
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
log.error("Error starting quest script: {}", questid, t);
dispose(c);
}
}
@@ -101,7 +100,7 @@ public class QuestScriptManager extends AbstractScriptManager {
c.setClickedNPC();
iv.invokeFunction("start", mode, type, selection);
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", e);
log.error("Error starting quest script: {}", getQM(c).getQuest(), e);
dispose(c);
}
}
@@ -140,11 +139,8 @@ public class QuestScriptManager extends AbstractScriptManager {
c.setClickedNPC();
iv.invokeFunction("end", (byte) 1, (byte) 0, 0);
}
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
log.error("Error starting quest script: {}", questid, t);
dispose(c);
}
}
@@ -156,7 +152,7 @@ public class QuestScriptManager extends AbstractScriptManager {
c.setClickedNPC();
iv.invokeFunction("end", mode, type, selection);
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", e);
log.error("Error ending quest script: {}", getQM(c).getQuest(), e);
dispose(c);
}
}
@@ -185,11 +181,8 @@ public class QuestScriptManager extends AbstractScriptManager {
c.setClickedNPC();
iv.invokeFunction("raiseOpen");
}
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
log.error("Error during quest script raiseOpen for quest: {}", questid, t);
dispose(c);
}
}

View File

@@ -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);
}
}