| 26 | |
| 27 | public class ContentRegister { |
| 28 | public static void initFilters() { |
| 29 | // test if Nucleaus plugin is present to keep auto-translated chat |
| 30 | final mindustry.mod.Mod nucleusPlugin = Vars.mods.getMod("xpdustry-nucleus") == null ? null : Vars.mods.getMod("xpdustry-nucleus").main; |
| 31 | |
| 32 | // filter for muted, rainbowed players, disabled chat, and tags |
| 33 | // register this filter at second position after anti-spam of mindustry and |
| 34 | // before others potential other filters |
| 35 | netServer.admins.chatFilters.insert(1, (p, m) -> { |
| 36 | TempData data = TempData.get(p); |
| 37 | |
| 38 | if (PVars.chat && data.isMuted) util.Players.err(p, "You're muted, you can't speak."); |
| 39 | else if (!PVars.chat && !p.admin) p.sendMessage("[scarlet]Chat disabled, only admins can't speak!"); |
| 40 | else { |
| 41 | Log.info(Strings.format("&lk@&fb&ly@&fr<&fi&lc@&fr: &fb&lw@&fr>", data.rainbowed ? "RAINBOWED: " : data.spectate() ? "VANISHED: " : "", data.noColorTag, data.noColorName, m)); |
| 42 | |
| 43 | if (data.spectate()) Call.sendChatMessage("[coral][[]:[white] " + m); |
| 44 | else if (nucleusPlugin != null) { |
| 45 | final fr.xpdustry.nucleus.core.translation.Translator translator = ((fr.xpdustry.nucleus.mindustry.NucleusPlugin) nucleusPlugin).getTranslator(); |
| 46 | final String stripedMessage = Strings.stripColors(m); |
| 47 | |
| 48 | TempData.localeOrdonedPlayer.each((k, v) -> { |
| 49 | String newMessage = m; |
| 50 | |
| 51 | if (!(k.contains("_") ? k.subSequence(0, k.indexOf("_")) : k).equals(data.locale.getLanguage())) { |
| 52 | try { |
| 53 | newMessage += " [lightgray](" |
| 54 | + translator.translate(stripedMessage, data.locale, v.first().locale) |
| 55 | .orTimeout(3l, java.util.concurrent.TimeUnit.SECONDS).join() |
| 56 | + ")"; |
| 57 | } catch (Exception e) { |
| 58 | Log.debug("Failed to translate message '" + stripedMessage + "' in language " + v.first().player.locale); |
| 59 | Log.debug("Error: " + e.getLocalizedMessage()); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | for (int i = 0; i < v.size; i++) { |
| 64 | Call.sendMessage(v.items[i].player.con, (PVars.tags ? data.tag : "") |
| 65 | + "[coral][[" + data.getName() + "[coral]]:[white] " + newMessage, newMessage, p); |
| 66 | } |
| 67 | }); |
| 68 | } else Call.sendMessage((PVars.tags ? data.tag : "") + "[coral][[" + data.getName() + "[coral]]:[white] " + m, m, p); |
| 69 | } |
| 70 | |
| 71 | return null; |
| 72 | }); |
| 73 | |
| 74 | // filter for players in GodMode |
| 75 | netServer.admins.addActionFilter(a -> { |
| 76 | TempData p = TempData.get(a.player); |
| 77 | if (p != null && p.inGodmode) { |
| 78 | if (a.type == ActionType.placeBlock) Call.constructFinish(a.tile, a.block, a.player.unit(), (byte) a.rotation, a.player.team(), a.config); |
| 79 | else if (a.type == ActionType.breakBlock) Call.deconstructFinish(a.tile, a.block, a.player.unit()); |
| 80 | } |
| 81 | return true; |
| 82 | }); |
| 83 | } |
| 84 | |
| 85 | public static void initEvents() { |