Skip to content

Commit 66d6242

Browse files
committed
implement random mode
1 parent 90bb687 commit 66d6242

4 files changed

Lines changed: 31 additions & 15 deletions

File tree

src/main/java/net/azisaba/lgw/core/LeonGunWar.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,13 @@ public void onEnable() {
181181
new PlayerControlListener());
182182

183183
// リスナーの登録 (modes)
184-
Bukkit.getPluginManager().registerEvents(new TeamDeathMatchListener(), this);
185-
Bukkit.getPluginManager().registerEvents(new HijackListener(), this);
186-
Bukkit.getPluginManager().registerEvents(new TDMNoLimitListener(), this);
187-
Bukkit.getPluginManager().registerEvents(new LeaderDeathMatchListener(), this);
188-
Bukkit.getPluginManager().registerEvents(new CustomTDMListener(), this);
184+
registerEvents(
185+
new TeamDeathMatchListener(),
186+
new HijackListener(),
187+
new TDMNoLimitListener(),
188+
new LeaderDeathMatchListener(),
189+
new CustomTDMListener()
190+
);
189191

190192
// リスナーの登録 (others)
191193
registerEvents(new NoArrowGroundListener(),

src/main/java/net/azisaba/lgw/core/configs/MapsConfig.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ public void loadConfig() throws IOException, InvalidConfigurationException {
8181
}
8282

8383
List<Area3D> areas = new ArrayList<>();
84-
for (String area : mapSection.getConfigurationSection("areas").getKeys(false)) {
85-
ConfigurationSection areaSection = mapSection.getConfigurationSection("areas." + area);
86-
Vector min = getLocation(areaSection.getConfigurationSection("min"));
87-
Vector max = getLocation(areaSection.getConfigurationSection("max"));
88-
areas.add(new Area3D(min, max));
84+
if (mapSection.getConfigurationSection("areas") != null) {
85+
for (String area : mapSection.getConfigurationSection("areas").getKeys(false)) {
86+
ConfigurationSection areaSection = mapSection.getConfigurationSection("areas." + area);
87+
Vector min = getLocation(areaSection.getConfigurationSection(".min"));
88+
Vector max = getLocation(areaSection.getConfigurationSection(".max"));
89+
areas.add(new Area3D(min, max));
90+
}
8991
}
9092

9193
GameMap gameMap = new GameMap(mapName, world, spawnMap, areas);
@@ -120,6 +122,7 @@ public Set<GameMap> getRandomMaps(int count) {
120122
}
121123
List<GameMap> shuffleList = new ArrayList<>(allGameMap);
122124
Collections.shuffle(shuffleList);
125+
shuffleList.removeIf(map -> !map.getHijackAreas().isEmpty());
123126

124127
return new HashSet<>(shuffleList.subList(0, count));
125128
}
@@ -145,9 +148,9 @@ public List<GameMap> getAllGameMap() {
145148
}
146149

147150
private Vector getLocation(ConfigurationSection section) {
148-
double x = section.getDouble("x");
149-
double y = section.getDouble("y");
150-
double z = section.getDouble("z");
151+
double x = section.getDouble(".x");
152+
double y = section.getDouble(".y");
153+
double z = section.getDouble(".z");
151154
return new Vector(x, y, z);
152155
}
153156
}

src/main/java/net/azisaba/lgw/core/sql/SQLConnection.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ public void update() throws SQLException {
9292
}
9393

9494
public void onDisable() {
95-
this.dataSource.close();
95+
if (this.dataSource != null) {
96+
this.dataSource.close();
97+
}
9698
}
9799

98100
public ResultSet executeQuery(String query, Object... args) {

src/main/java/net/azisaba/lgw/core/util/MatchMode.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public enum MatchMode {
4848
Chat.f("&cHIJACK"),
4949
Chat.f("&7終了時に &cキャプチャーポイント &7が多いチームの勝利"),
5050
Duration.ofMinutes(10),
51-
Arrays.asList("hijack", "hj")
51+
Arrays.asList("hijack", "hj", "h")
5252
);
5353

5454

@@ -67,6 +67,15 @@ public enum MatchMode {
6767
}
6868

6969
public static MatchMode getFromString(String text) {
70+
if (text.equalsIgnoreCase("[random]") || text.equalsIgnoreCase("r")) {
71+
int rand = (int) (Math.random() * 2);
72+
if (rand == 0) {
73+
return LEADER_DEATH_MATCH_POINT;
74+
} else {
75+
return HIJACK;
76+
}
77+
}
78+
7079
String suggest = text.replace(" ", "").toLowerCase();
7180
return Arrays.stream(values())
7281
.filter(mode -> mode.suggests.contains(suggest))

0 commit comments

Comments
 (0)