1- package com .github .elic0de .thejpspit . spigot ;
1+ package com .github .elic0de .thejpspit ;
22
33import co .aikar .commands .PaperCommandManager ;
44import com .fatboyindustrial .gsonjavatime .Converters ;
5- import com .github .elic0de .thejpspit .spigot .command .PitCommand ;
6- import com .github .elic0de .thejpspit .spigot .command .SpawnCommand ;
7- import com .github .elic0de .thejpspit .spigot .config .PitPreferences ;
8- import com .github .elic0de .thejpspit .spigot .database .Database ;
9- import com .github .elic0de .thejpspit .spigot .database .SqLiteDatabase ;
10- import com .github .elic0de .thejpspit .spigot .game .Game ;
11- import com .github .elic0de .thejpspit .spigot .hook .EconomyHook ;
12- import com .github .elic0de .thejpspit .spigot .hook .Hook ;
13- import com .github .elic0de .thejpspit .spigot .hook .VaultEconomyHook ;
14- import com .github .elic0de .thejpspit .spigot .item .ItemManager ;
15- import com .github .elic0de .thejpspit .spigot .item .items .*;
16- import com .github .elic0de .thejpspit .spigot .listener .CombatTagger ;
17- import com .github .elic0de .thejpspit .spigot .listener .EventListener ;
18- import com .github .elic0de .thejpspit .spigot .network .PluginMessageReceiver ;
19- import com .github .elic0de .thejpspit .spigot .nms .PacketManager ;
20- import com .github .elic0de .thejpspit .spigot .nms .PacketManager1_19_R1 ;
21- import com .github .elic0de .thejpspit .spigot .player .PitPlayer ;
22- import com .github .elic0de .thejpspit .spigot .player .PitPlayerManager ;
23- import com .github .elic0de .thejpspit .spigot .queue .QueueManager ;
24- import com .github .elic0de .thejpspit .spigot .task .QueueTask ;
25- import com .github .elic0de .thejpspit .spigot .util .KillAssistHelper ;
26- import com .github .elic0de .thejpspit .spigot .util .KillRatingHelper ;
27- import com .github .elic0de .thejpspit .spigot .villager .VillagerNPCManager ;
28- import com .github .elic0de .thejpspit .spigot .villager .villagers .ShopVillager ;
5+ import com .github .elic0de .thejpspit .command .PitChatCommand ;
6+ import com .github .elic0de .thejpspit .command .PitCommand ;
7+ import com .github .elic0de .thejpspit .command .SpawnCommand ;
8+ import com .github .elic0de .thejpspit .config .PitPreferences ;
9+ import com .github .elic0de .thejpspit .config .Settings ;
10+ import com .github .elic0de .thejpspit .database .Database ;
11+ import com .github .elic0de .thejpspit .database .SqLiteDatabase ;
12+ import com .github .elic0de .thejpspit .hook .PlaceholderHook ;
13+ import com .github .elic0de .thejpspit .leveler .Levels ;
14+ import com .github .elic0de .thejpspit .listener .CombatTagger ;
15+ import com .github .elic0de .thejpspit .player .PitPlayer ;
16+ import com .github .elic0de .thejpspit .player .PitPlayerManager ;
17+ import com .github .elic0de .thejpspit .game .Game ;
18+ import com .github .elic0de .thejpspit .hook .EconomyHook ;
19+ import com .github .elic0de .thejpspit .hook .Hook ;
20+ import com .github .elic0de .thejpspit .hook .VaultEconomyHook ;
21+ import com .github .elic0de .thejpspit .item .ItemManager ;
22+ import com .github .elic0de .thejpspit .listener .BlockPlaceListener ;
23+ import com .github .elic0de .thejpspit .listener .EventListener ;
24+ import com .github .elic0de .thejpspit .util .KillAssistHelper ;
25+ import com .github .elic0de .thejpspit .util .KillRatingHelper ;
26+ import com .github .elic0de .thejpspit .villager .VillagerNPCManager ;
27+ import com .github .elic0de .thejpspit .villager .villagers .ShopVillager ;
2928import com .google .gson .Gson ;
3029import com .google .gson .GsonBuilder ;
30+ import me .clip .placeholderapi .configuration .PlaceholderAPIConfig ;
31+ import net .william278 .annotaml .Annotaml ;
3132import org .bukkit .Bukkit ;
3233import org .bukkit .GameRule ;
33- import org .bukkit .attribute .Attribute ;
3434import org .bukkit .plugin .PluginManager ;
3535import org .bukkit .plugin .java .JavaPlugin ;
3636
37-
38-
37+ import java .io .File ;
38+ import java .io .IOException ;
39+ import java .lang .reflect .InvocationTargetException ;
3940import java .util .ArrayList ;
4041import java .util .List ;
4142import java .util .Optional ;
4546public final class TheJpsPit extends JavaPlugin {
4647
4748 private static TheJpsPit instance ;
49+ private Settings settings ;
4850 private Game game ;
4951 private Database database ;
5052 private KillRatingHelper ratingHelper ;
5153
5254 private KillAssistHelper assistKillHelper ;
53- private QueueManager queueManager ;
54- private QueueTask queueTask ;
5555 private List <Hook > hooks = new ArrayList <>();
5656
5757 private Optional <PitPreferences > pitPreferences ;
5858
59- private PacketManager packetManager ;
60-
6159 public static TheJpsPit getInstance () {
6260 return instance ;
6361 }
@@ -67,9 +65,25 @@ public void onLoad() {
6765 instance = this ;
6866 }
6967
68+ private void loadConfig () throws RuntimeException {
69+ try {
70+ this .settings = Annotaml .create (new File (getDataFolder (), "config.yml" ), Settings .class ).get ();
71+ } catch (IOException | InvocationTargetException | InstantiationException |
72+ IllegalAccessException e ) {
73+ getLogger ().log (Level .SEVERE , "Failed to load configuration files" , e );
74+ throw new RuntimeException (e );
75+ }
76+ }
77+
78+ public void reload () {
79+ loadConfig ();
80+ Levels .initialize ();
81+ }
82+
7083 @ Override
7184 public void onEnable () {
7285 // Initialize TheJpsPit
86+ this .loadConfig ();
7387 saveConfig ();
7488 final AtomicBoolean initialized = new AtomicBoolean (true );
7589 game = new Game ();
@@ -88,17 +102,9 @@ public void onEnable() {
88102
89103 assistKillHelper = new KillAssistHelper ();
90104 ratingHelper = new KillRatingHelper (0 );
91- queueManager = new QueueManager ();
92- queueTask = new QueueTask ();
93105
94106 setPreferences ();
95- setPacketManager ();
96-
97- getServer ().getMessenger ()
98- .registerIncomingPluginChannel (this , PluginMessageReceiver .BUNGEE_CHANNEL_ID ,
99- new PluginMessageReceiver ());
100- getServer ().getMessenger ()
101- .registerOutgoingPluginChannel (this , PluginMessageReceiver .BUNGEE_CHANNEL_ID );
107+ //setPacketManager();
102108
103109 registerCommands ();
104110 registerListener ();
@@ -111,7 +117,7 @@ public void onEnable() {
111117 world .setGameRule (GameRule .KEEP_INVENTORY , true );
112118 });
113119
114- createItems ();
120+ ItemManager . createItems ();
115121 createNPCs ();
116122
117123 Bukkit .getOnlinePlayers ().forEach (player -> {
@@ -129,7 +135,6 @@ public void onEnable() {
129135 if (updateNeeded ) {
130136 database .updateUserData (pitPlayer );
131137 }
132-
133138 });
134139 }
135140
@@ -144,7 +149,7 @@ private void setPreferences() {
144149 this .pitPreferences = preferences ;
145150 }
146151
147- private void setPacketManager () {
152+ /* private void setPacketManager() {
148153 final String serverVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3].trim();
149154 PacketManager packetManager;
150155 switch (serverVersion) {
@@ -155,7 +160,7 @@ private void setPacketManager() {
155160 throw new RuntimeException("Failed to create version specific server accessor");
156161 }
157162 this.packetManager = packetManager;
158- }
163+ }*/
159164
160165 private void registerCommands () {
161166 PaperCommandManager commandManager = new PaperCommandManager (this );
@@ -164,26 +169,23 @@ private void registerCommands() {
164169
165170 commandManager .registerCommand (new PitCommand ());
166171 commandManager .registerCommand (new SpawnCommand ());
172+ commandManager .registerCommand (new PitChatCommand ());
167173 }
168174
169175 private void registerListener () {
170176 new EventListener ();
171177 new CombatTagger ();
178+ new BlockPlaceListener ();
172179 }
173180
174181 private void registerHooks () {
175182 final PluginManager plugins = Bukkit .getPluginManager ();
176183 if (plugins .getPlugin ("Vault" ) != null ) {
177184 this .registerHook (new VaultEconomyHook (this ));
178185 }
179- }
180-
181- private void createItems () {
182- ItemManager .register (new ItemDiamondSword ());
183- ItemManager .register (new ItemDiamondChestPlate ());
184- ItemManager .register (new ItemDiamondBoots ());
185- ItemManager .register (new ItemObsidian ());
186- ItemManager .register (new ItemVividSword ());
186+ if (plugins .getPlugin ("PlaceholderAPI" ) != null ) {
187+ new PlaceholderHook ().register ();
188+ }
187189 }
188190
189191 private void createNPCs () {
@@ -192,18 +194,18 @@ private void createNPCs() {
192194
193195 @ Override
194196 public void onDisable () {
195- pitPreferences .ifPresent (preferences -> database .updatePitPreferences (preferences ));
196197 // Plugin shutdown logic
197198 if (database != null ) {
198199 database .terminate ();
199200 }
200201 game .getTask ().stop ();
201202
202- queueTask .stop ();
203-
204203 getServer ().getMessenger ().unregisterOutgoingPluginChannel (this );
205204 getServer ().getMessenger ().unregisterIncomingPluginChannel (this );
206205
206+ // 置かれたブロックを削除
207+ BlockPlaceListener .restoreBlocks ();
208+
207209 Bukkit .getOnlinePlayers ().forEach (player -> {
208210 final PitPlayer pitPlayer = PitPlayerManager .getPitPlayer (player );
209211 game .leave (pitPlayer );
@@ -214,6 +216,10 @@ public void onDisable() {
214216 Bukkit .getScheduler ().cancelTasks (this );
215217 }
216218
219+ public Settings getSettings () {
220+ return settings ;
221+ }
222+
217223 private List <Hook > getHooks () {
218224 return hooks ;
219225 }
@@ -254,17 +260,10 @@ public KillAssistHelper getAssistKillHelper() {
254260 return assistKillHelper ;
255261 }
256262
257- public QueueManager getQueueManager () {
258- return queueManager ;
259- }
260-
261263 public Optional <PitPreferences > getPitPreferences () {
262264 return pitPreferences ;
263265 }
264266
265- public PacketManager getPacketManager () {
266- return packetManager ;
267- }
268267
269268 public Gson getGson () {
270269 return Converters .registerOffsetDateTime (new GsonBuilder ().excludeFieldsWithoutExposeAnnotation ()).create ();
0 commit comments