Skip to content

Commit 90b2327

Browse files
committed
ブロックのリスナーを登録
1 parent 71abdb3 commit 90b2327

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/main/java/com/github/elic0de/thejpspit/spigot/TheJpsPit.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.github.elic0de.thejpspit.spigot.command.PitCommand;
66
import com.github.elic0de.thejpspit.spigot.command.SpawnCommand;
77
import com.github.elic0de.thejpspit.spigot.config.PitPreferences;
8+
import com.github.elic0de.thejpspit.spigot.config.Settings;
89
import com.github.elic0de.thejpspit.spigot.database.Database;
910
import com.github.elic0de.thejpspit.spigot.database.SqLiteDatabase;
1011
import com.github.elic0de.thejpspit.spigot.game.Game;
@@ -21,6 +22,7 @@
2122
import com.github.elic0de.thejpspit.spigot.item.items.ItemTurtleShell;
2223
import com.github.elic0de.thejpspit.spigot.item.items.ItemUltimateSword;
2324
import com.github.elic0de.thejpspit.spigot.item.items.ItemVividSword;
25+
import com.github.elic0de.thejpspit.spigot.listener.BlockPlaceListener;
2426
import com.github.elic0de.thejpspit.spigot.listener.CombatTagger;
2527
import com.github.elic0de.thejpspit.spigot.listener.EventListener;
2628
import com.github.elic0de.thejpspit.spigot.network.PluginMessageReceiver;
@@ -34,11 +36,15 @@
3436
import com.github.elic0de.thejpspit.spigot.villager.villagers.ShopVillager;
3537
import com.google.gson.Gson;
3638
import com.google.gson.GsonBuilder;
39+
import java.io.File;
40+
import java.io.IOException;
41+
import java.lang.reflect.InvocationTargetException;
3742
import java.util.ArrayList;
3843
import java.util.List;
3944
import java.util.Optional;
4045
import java.util.concurrent.atomic.AtomicBoolean;
4146
import java.util.logging.Level;
47+
import net.william278.annotaml.Annotaml;
4248
import org.bukkit.Bukkit;
4349
import org.bukkit.GameRule;
4450
import org.bukkit.plugin.PluginManager;
@@ -47,6 +53,7 @@
4753
public final class TheJpsPit extends JavaPlugin {
4854

4955
private static TheJpsPit instance;
56+
private Settings settings;
5057
private Game game;
5158
private Database database;
5259
private KillRatingHelper ratingHelper;
@@ -67,9 +74,25 @@ public void onLoad() {
6774
instance = this;
6875
}
6976

77+
private void loadConfig() throws RuntimeException {
78+
try {
79+
this.settings = Annotaml.create(new File(getDataFolder(), "config.yml"), Settings.class)
80+
.get();
81+
} catch (IOException | InvocationTargetException | InstantiationException |
82+
IllegalAccessException e) {
83+
getLogger().log(Level.SEVERE, "Failed to load configuration files", e);
84+
throw new RuntimeException(e);
85+
}
86+
}
87+
88+
public void reload() {
89+
loadConfig();
90+
}
91+
7092
@Override
7193
public void onEnable() {
7294
// Initialize TheJpsPit
95+
this.loadConfig();
7396
saveConfig();
7497
final AtomicBoolean initialized = new AtomicBoolean(true);
7598
game = new Game();
@@ -169,6 +192,7 @@ private void registerCommands() {
169192
private void registerListener() {
170193
new EventListener();
171194
new CombatTagger();
195+
new BlockPlaceListener();
172196
}
173197

174198
private void registerHooks() {
@@ -207,6 +231,9 @@ public void onDisable() {
207231
getServer().getMessenger().unregisterOutgoingPluginChannel(this);
208232
getServer().getMessenger().unregisterIncomingPluginChannel(this);
209233

234+
// 置かれたブロックを削除
235+
BlockPlaceListener.removeBlocks();
236+
210237
Bukkit.getOnlinePlayers().forEach(player -> {
211238
final PitPlayer pitPlayer = PitPlayerManager.getPitPlayer(player);
212239
game.leave(pitPlayer);
@@ -217,6 +244,10 @@ public void onDisable() {
217244
Bukkit.getScheduler().cancelTasks(this);
218245
}
219246

247+
public Settings getSettings() {
248+
return settings;
249+
}
250+
220251
private List<Hook> getHooks() {
221252
return hooks;
222253
}

0 commit comments

Comments
 (0)