Commits
md_5 authored 44016b1dfc7
24 24 | |
25 25 | - public DedicatedServer(File file, DedicatedServerSettings dedicatedserversettings, DataFixer datafixer, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory, String s) { |
26 26 | - super(file, Proxy.NO_PROXY, datafixer, new CommandDispatcher(true), yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, usercache, worldloadlistenerfactory, s); |
27 27 | + // CraftBukkit start - Signature changed |
28 28 | + public DedicatedServer(joptsimple.OptionSet options, DedicatedServerSettings dedicatedserversettings, DataFixer datafixer, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory, String s) { |
29 29 | + super(options, Proxy.NO_PROXY, datafixer, new CommandDispatcher().init(true), yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, usercache, worldloadlistenerfactory, s); |
30 30 | + // CraftBukkit end |
31 31 | this.propertyManager = dedicatedserversettings; |
32 32 | this.remoteControlCommandListener = new RemoteControlCommandListener(this); |
33 33 | Thread thread = new Thread("Server Infinisleeper") { |
34 - | |
34 + | |
35 35 | public boolean init() throws IOException { |
36 36 | Thread thread = new Thread("Server console handler") { |
37 37 | public void run() { |
38 38 | - BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)); |
39 39 | + // CraftBukkit start |
40 40 | + if (!org.bukkit.craftbukkit.Main.useConsole) { |
41 41 | + return; |
42 42 | + } |
43 43 | + jline.console.ConsoleReader bufferedreader = reader; |
44 + | + |
45 + | + // MC-33041, SPIGOT-5538: if System.in is not valid due to javaw, then return |
46 + | + try { |
47 + | + System.in.available(); |
48 + | + } catch (IOException ex) { |
49 + | + return; |
50 + | + } |
44 51 | + // CraftBukkit end |
45 52 | |
46 53 | String s; |
47 54 | |
48 55 | try { |
49 56 | - while (!DedicatedServer.this.isStopped() && DedicatedServer.this.isRunning() && (s = bufferedreader.readLine()) != null) { |
50 57 | - DedicatedServer.this.issueCommand(s, DedicatedServer.this.getServerCommandListener()); |
51 58 | + // CraftBukkit start - JLine disabling compatibility |
52 59 | + while (!DedicatedServer.this.isStopped() && DedicatedServer.this.isRunning()) { |
53 60 | + if (org.bukkit.craftbukkit.Main.useJline) { |
65 72 | + } |
66 73 | + continue; |
67 74 | + } |
68 75 | + if (s.trim().length() > 0) { // Trim to filter lines which are just spaces |
69 76 | + DedicatedServer.this.issueCommand(s, DedicatedServer.this.getServerCommandListener()); |
70 77 | + } |
71 78 | + // CraftBukkit end |
72 79 | } |
73 80 | } catch (IOException ioexception) { |
74 81 | DedicatedServer.LOGGER.error("Exception handling console input", ioexception); |
75 - | |
82 + | |
76 83 | } |
77 84 | }; |
78 85 | |
79 86 | + // CraftBukkit start - TODO: handle command-line logging arguments |
80 87 | + java.util.logging.Logger global = java.util.logging.Logger.getLogger(""); |
81 88 | + global.setUseParentHandlers(false); |
82 89 | + for (java.util.logging.Handler handler : global.getHandlers()) { |
83 90 | + global.removeHandler(handler); |
84 91 | + } |
85 92 | + global.addHandler(new org.bukkit.craftbukkit.util.ForwardLogHandler()); |
93 100 | + |
94 101 | + new org.bukkit.craftbukkit.util.TerminalConsoleWriterThread(System.out, this.reader).start(); |
95 102 | + |
96 103 | + System.setOut(new PrintStream(new LoggerOutputStream(logger, Level.INFO), true)); |
97 104 | + System.setErr(new PrintStream(new LoggerOutputStream(logger, Level.WARN), true)); |
98 105 | + // CraftBukkit end |
99 106 | + |
100 107 | thread.setDaemon(true); |
101 108 | thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(DedicatedServer.LOGGER)); |
102 109 | thread.start(); |
103 - | |
110 + | |
104 111 | return false; |
105 112 | } |
106 113 | |
107 114 | + // CraftBukkit start |
108 115 | + this.a((PlayerList) (new DedicatedPlayerList(this))); |
109 116 | + server.loadPlugins(); |
110 117 | + server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.STARTUP); |
111 118 | + // CraftBukkit end |
112 119 | + |
113 120 | if (!this.getOnlineMode()) { |
114 121 | DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!"); |
115 122 | DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware."); |
116 - | |
123 + | |
117 124 | if (!NameReferencingFileConverter.e(this)) { |
118 125 | return false; |
119 126 | } else { |
120 127 | - this.a((PlayerList) (new DedicatedPlayerList(this))); |
121 128 | + this.convertable = new Convertable(server.getWorldContainer().toPath(), server.getWorldContainer().toPath().resolve("../backups"), this.dataConverterManager); // CraftBukkit - moved from MinecraftServer constructor |
122 129 | long i = SystemUtils.getMonotonicNanos(); |
123 130 | String s = dedicatedserverproperties.levelSeed; |
124 131 | String s1 = dedicatedserverproperties.generatorSettings; |
125 - | |
132 + | |
126 133 | if (worldtype == WorldType.FLAT) { |
127 134 | jsonobject.addProperty("flat_world_options", s1); |
128 135 | } else if (!s1.isEmpty()) { |
129 136 | - jsonobject = ChatDeserializer.a(s1); |
130 137 | + // CraftBukkit start |
131 138 | + try { |
132 139 | + jsonobject = ChatDeserializer.a(s1); |
133 140 | + } catch (Exception ex) { |
134 141 | + DedicatedServer.LOGGER.warn("Invalid generator-settings, ignoring", ex); |
135 142 | + } |
136 143 | + // CraftBukkit end |
137 144 | } |
138 145 | |
139 146 | this.a(this.getWorld(), this.getWorld(), j, worldtype, jsonobject); |
140 - | |
147 + | |
141 148 | DedicatedServer.LOGGER.info("Starting remote control listener"); |
142 149 | this.remoteControlListener = new RemoteControlListener(this); |
143 150 | this.remoteControlListener.a(); |
144 151 | + this.remoteConsole = new org.bukkit.craftbukkit.command.CraftRemoteConsoleCommandSender(this.remoteControlCommandListener); // CraftBukkit |
145 152 | } |
146 153 | |
147 154 | if (this.getMaxTickTime() > 0L) { |
148 - | |
155 + | |
149 156 | this.remoteStatusListener.b(); |
150 157 | } |
151 158 | |
152 159 | + System.exit(0); // CraftBukkit |
153 160 | } |
154 161 | |
155 162 | @Override |
156 - | |
163 + | |
157 164 | while (!this.serverCommandQueue.isEmpty()) { |
158 165 | ServerCommand servercommand = (ServerCommand) this.serverCommandQueue.remove(0); |
159 166 | |
160 167 | - this.getCommandDispatcher().a(servercommand.source, servercommand.command); |
161 168 | + // CraftBukkit start - ServerCommand for preprocessing |
162 169 | + ServerCommandEvent event = new ServerCommandEvent(console, servercommand.command); |
163 170 | + server.getPluginManager().callEvent(event); |
164 171 | + if (event.isCancelled()) continue; |
165 172 | + servercommand = new ServerCommand(event.getCommand(), servercommand.source); |
166 173 | + |
167 174 | + // this.getCommandDispatcher().a(servercommand.source, servercommand.command); // Called in dispatchServerCommand |
168 175 | + server.dispatchServerCommand(console, servercommand); |
169 176 | + // CraftBukkit end |
170 177 | } |
171 178 | |
172 179 | } |
173 - | |
180 + | |
174 181 | |
175 182 | @Override |
176 183 | public String getPlugins() { |
177 184 | - return ""; |
178 185 | + // CraftBukkit start - Whole method |
179 186 | + StringBuilder result = new StringBuilder(); |
180 187 | + org.bukkit.plugin.Plugin[] plugins = server.getPluginManager().getPlugins(); |
181 188 | + |
182 189 | + result.append(server.getName()); |
183 190 | + result.append(" on Bukkit "); |
211 218 | + server.getPluginManager().callEvent(event); |
212 219 | + if (event.isCancelled()) { |
213 220 | + return; |
214 221 | + } |
215 222 | + ServerCommand serverCommand = new ServerCommand(event.getCommand(), remoteControlCommandListener.getWrapper()); |
216 223 | + server.dispatchServerCommand(remoteConsole, serverCommand); |
217 224 | + // CraftBukkit end |
218 225 | }); |
219 226 | return this.remoteControlCommandListener.getMessages(); |
220 227 | } |
221 - | |
228 + | |
222 229 | public boolean a(GameProfile gameprofile) { |
223 230 | return false; |
224 231 | } |
225 232 | + |
226 233 | + // CraftBukkit start |
227 234 | + @Override |
228 235 | + public boolean isDebugging() { |
229 236 | + return this.getDedicatedServerProperties().debug; |
230 237 | + } |
231 238 | + |