-
-
Notifications
You must be signed in to change notification settings - Fork 211
/
SpongeGame.java
229 lines (193 loc) · 7.25 KB
/
SpongeGame.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.spongepowered.api.Client;
import org.spongepowered.api.Game;
import org.spongepowered.api.Platform;
import org.spongepowered.api.Server;
import org.spongepowered.api.data.DataManager;
import org.spongepowered.api.event.EventManager;
import org.spongepowered.api.network.channel.ChannelManager;
import org.spongepowered.api.plugin.PluginManager;
import org.spongepowered.api.registry.BuilderProvider;
import org.spongepowered.api.registry.FactoryProvider;
import org.spongepowered.api.service.ServiceProvider;
import org.spongepowered.api.sql.SqlManager;
import org.spongepowered.api.util.metric.MetricsConfigManager;
import org.spongepowered.common.config.PluginConfigManager;
import org.spongepowered.common.registry.RegistryHolderLogic;
import org.spongepowered.common.registry.SpongeRegistryHolder;
import org.spongepowered.common.scheduler.AsyncScheduler;
import org.spongepowered.common.server.ServerConsoleSystemSubject;
import org.spongepowered.common.util.LocaleCache;
import java.nio.file.Path;
import java.util.Locale;
@Singleton
public final class SpongeGame implements Game, SpongeRegistryHolder {
private final Platform platform;
private final BuilderProvider builderProvider;
private final FactoryProvider factoryProvider;
private final DataManager dataManager;
private final PluginManager pluginManager;
private final EventManager eventManager;
private final PluginConfigManager configManager;
private final ChannelManager channelManager;
private final MetricsConfigManager metricsConfigManager;
private final SqlManager sqlManager;
private final ServiceProvider.GameScoped serviceProvider;
private final AsyncScheduler asyncScheduler;
private RegistryHolderLogic registryHolder;
private Client client;
private Server server;
private ServerConsoleSystemSubject systemSubject;
@Inject
public SpongeGame(final Platform platform, final BuilderProvider builderProvider,
final FactoryProvider factoryProvider, final DataManager dataManager, final PluginManager pluginManager,
final EventManager eventManager, final PluginConfigManager configManager, final ChannelManager channelManager,
final MetricsConfigManager metricsConfigManager, final SqlManager sqlManager, final ServiceProvider.GameScoped serviceProvider) {
this.platform = platform;
this.builderProvider = builderProvider;
this.factoryProvider = factoryProvider;
this.dataManager = dataManager;
this.pluginManager = pluginManager;
this.eventManager = eventManager;
this.configManager = configManager;
this.channelManager = channelManager;
this.metricsConfigManager = metricsConfigManager;
this.sqlManager = sqlManager;
this.serviceProvider = serviceProvider;
this.asyncScheduler = new AsyncScheduler();
}
@Override
public Path gameDirectory() {
return SpongeCommon.gameDirectory();
}
@Override
public ServerConsoleSystemSubject systemSubject() {
if (this.systemSubject == null) {
this.systemSubject = new ServerConsoleSystemSubject();
}
return this.systemSubject;
}
@Override
public Platform platform() {
return this.platform;
}
@Override
public BuilderProvider builderProvider() {
return this.builderProvider;
}
@Override
public FactoryProvider factoryProvider() {
return this.factoryProvider;
}
@Override
public DataManager dataManager() {
return this.dataManager;
}
@Override
public PluginManager pluginManager() {
return this.pluginManager;
}
@Override
public EventManager eventManager() {
return this.eventManager;
}
@Override
public PluginConfigManager configManager() {
return this.configManager;
}
@Override
public ChannelManager channelManager() {
return this.channelManager;
}
@Override
public MetricsConfigManager metricsConfigManager() {
return this.metricsConfigManager;
}
@Override
public SqlManager sqlManager() {
return this.sqlManager;
}
@Override
public ServiceProvider.GameScoped serviceProvider() {
return this.serviceProvider;
}
@Override
public AsyncScheduler asyncScheduler() {
return this.asyncScheduler;
}
@Override
public Locale locale(final String locale) {
return LocaleCache.getLocale(Preconditions.checkNotNull(locale));
}
@Override
public boolean isServerAvailable() {
if (this.client != null) {
return this.client.server().isPresent();
}
return this.server != null;
}
@Override
public Server server() {
if (this.client != null) {
return this.client.server().orElseThrow(() -> new IllegalStateException("The singleplayer server is not available!"));
}
Preconditions.checkState(this.server != null, "The dedicated server is not available!");
return this.server;
}
public void setServer(final Server server) {
this.server = server;
}
@Override
public boolean isClientAvailable() {
return this.client != null;
}
@Override
public Client client() {
Preconditions.checkState(this.client != null, "The client is not available!");
return this.client;
}
public void setClient(final Client client) {
this.client = client;
}
@Override
public RegistryHolderLogic registryHolder() {
if (this.registryHolder == null) {
this.registryHolder = new RegistryHolderLogic();
}
return this.registryHolder;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("platform", this.platform)
.toString();
}
}