Skip to content

Commit 38673d8

Browse files
committed
別の機種で開発するためアップ
1 parent 81ae5dd commit 38673d8

18 files changed

Lines changed: 367 additions & 7 deletions

File tree

pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
<id>minebench-repo</id>
8787
<url>https://repo.minebench.de/</url>
8888
</repository>
89+
<repository>
90+
<id>jitpack.io</id>
91+
<url>https://jitpack.io</url>
92+
</repository>
8993
</repositories>
9094

9195
<dependencies>
@@ -120,5 +124,22 @@
120124
<version>1.6-SNAPSHOT</version>
121125
<scope>compile</scope>
122126
</dependency>
127+
<dependency>
128+
<groupId>dev.dejvokep</groupId>
129+
<artifactId>boosted-yaml</artifactId>
130+
<version>1.3</version>
131+
</dependency>
132+
<dependency>
133+
<groupId>net.william278</groupId>
134+
<artifactId>Annotaml</artifactId>
135+
<version>2.0.1</version>
136+
<scope>compile</scope>
137+
</dependency>
138+
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
139+
<dependency>
140+
<groupId>com.zaxxer</groupId>
141+
<artifactId>HikariCP</artifactId>
142+
<version>5.0.1</version>
143+
</dependency>
123144
</dependencies>
124145
</project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.github.elic0de.battleroyale.chest;
2+
3+
public class BonusChest {
4+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.github.elic0de.battleroyale.config;
2+
3+
public class BonusChestConfig {
4+
5+
6+
7+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.github.elic0de.battleroyale.config;
2+
3+
import lombok.Getter;
4+
import org.bukkit.Material;
5+
import org.bukkit.inventory.ItemStack;
6+
7+
@Getter
8+
public class KitConfig {
9+
10+
private final String name;
11+
private final String description;
12+
private final Material icon;
13+
private final ItemStack[] contents;
14+
15+
public KitConfig(String name, String description, Material icon, ItemStack[] contents) {
16+
this.name = name;
17+
this.description = description;
18+
this.icon = icon;
19+
this.contents = contents;
20+
}
21+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.github.elic0de.battleroyale.config;
2+
3+
import com.github.elic0de.battleroyale.game.GameType;
4+
import net.william278.annotaml.YamlComment;
5+
import net.william278.annotaml.YamlFile;
6+
7+
@YamlFile
8+
public class Settings {
9+
10+
@YamlComment("開始までの人数")
11+
public int StartPeopleNum;
12+
13+
@YamlComment("ゲーム時間")
14+
public int AutoGameTime; // ゲーム時間
15+
16+
@YamlComment("ボーダーサイズ")
17+
public int BorderSize; // ボーダーのサイズ
18+
19+
@YamlComment("人数が揃ってゲームが始まるまでの時間")
20+
public int CountDownTime; // 人数がそろってゲームが始まるまでの時間
21+
22+
@YamlComment("ゲームが終わって次のゲームに行くまでの時間")
23+
public int CoolTime; // ゲームが終わって次のゲームに行くまでの時間
24+
25+
@YamlComment("ソロやチームをゲームタイプ 例: ")
26+
public GameType gameType;
27+
28+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.github.elic0de.battleroyale.database;
2+
3+
import com.github.elic0de.battleroyale.BattleRoyale;
4+
import org.jetbrains.annotations.NotNull;
5+
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
import java.nio.charset.StandardCharsets;
9+
import java.util.Objects;
10+
import java.util.logging.Level;
11+
import java.util.regex.Matcher;
12+
import java.util.regex.Pattern;
13+
14+
public abstract class Database {
15+
16+
protected final BattleRoyale plugin;
17+
private final String schemaFile;
18+
private boolean loaded;
19+
20+
protected Database(@NotNull BattleRoyale plugin, @NotNull String schemaFile) {
21+
this.plugin = plugin;
22+
this.schemaFile = "database/" + schemaFile;
23+
}
24+
25+
@NotNull
26+
protected final String[] getSchema() {
27+
try (InputStream schemaStream = Objects.requireNonNull(plugin.getResource(schemaFile))) {
28+
final String schema = new String(schemaStream.readAllBytes(), StandardCharsets.UTF_8);
29+
return format(schema).split(";");
30+
} catch (IOException e) {
31+
plugin.getLogger().log(Level.SEVERE, "Failed to load database schema", e);
32+
}
33+
return new String[0];
34+
}
35+
36+
@NotNull
37+
protected final String format(@NotNull String statement) {
38+
final Pattern pattern = Pattern.compile("%(\\w+)%");
39+
final Matcher matcher = pattern.matcher(statement);
40+
final StringBuilder sb = new StringBuilder();
41+
while (matcher.find()) {
42+
final Table table = Table.match(matcher.group(1));
43+
matcher.appendReplacement(sb, plugin.getSettings().getTableName(table));
44+
}
45+
matcher.appendTail(sb);
46+
return sb.toString();
47+
}
48+
49+
50+
public abstract void initialize() throws RuntimeException;
51+
52+
public abstract void close();
53+
54+
public boolean hasLoaded() {
55+
return loaded;
56+
}
57+
58+
protected void setLoaded(boolean loaded) {
59+
this.loaded = loaded;
60+
}
61+
62+
public enum Type {
63+
MYSQL("MySQL"),
64+
SQLITE("SQLite");
65+
@NotNull
66+
private final String displayName;
67+
68+
Type(@NotNull String displayName) {
69+
this.displayName = displayName;
70+
}
71+
72+
@NotNull
73+
public String getDisplayName() {
74+
return displayName;
75+
}
76+
}
77+
78+
79+
public enum Table {
80+
USER_DATA("_users");
81+
82+
@NotNull
83+
private final String defaultName;
84+
85+
Table(@NotNull String defaultName) {
86+
this.defaultName = defaultName;
87+
}
88+
89+
@NotNull
90+
public static Database.Table match(@NotNull String placeholder) throws IllegalArgumentException {
91+
return Table.valueOf(placeholder.toUpperCase());
92+
}
93+
94+
@NotNull
95+
public String getDefaultName() {
96+
return defaultName;
97+
}
98+
}
99+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.github.elic0de.battleroyale.database;
2+
3+
import com.github.elic0de.battleroyale.BattleRoyale;
4+
import com.zaxxer.hikari.HikariDataSource;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
import java.sql.Connection;
8+
import java.sql.SQLException;
9+
import java.util.Properties;
10+
11+
public class MySqlDatabase extends Database {
12+
13+
/**
14+
* Name of the Hikari connection pool
15+
*/
16+
private static final String DATA_POOL_NAME = "BattleRoyaleHikariPool";
17+
18+
/**
19+
* The Hikari data source
20+
*/
21+
private HikariDataSource dataSource;
22+
23+
private Connection getConnection() throws SQLException {
24+
return dataSource.getConnection();
25+
}
26+
27+
private void setConnection() {
28+
final Settings settings = plugin.getSettings();
29+
30+
// Create jdbc driver connection url
31+
final String jdbcUrl = "jdbc:mysql://" + settings.getMySqlHost() + ":" + settings.getMySqlPort() + "/"
32+
+ settings.getMySqlDatabase() + settings.getMySqlConnectionParameters();
33+
dataSource = new HikariDataSource();
34+
dataSource.setJdbcUrl(jdbcUrl);
35+
36+
// Authenticate
37+
dataSource.setUsername(settings.getMySqlUsername());
38+
dataSource.setPassword(settings.getMySqlPassword());
39+
40+
// Set connection pool options
41+
dataSource.setMaximumPoolSize(settings.getMySqlConnectionPoolSize());
42+
dataSource.setMinimumIdle(settings.getMySqlConnectionPoolIdle());
43+
dataSource.setMaxLifetime(settings.getMySqlConnectionPoolLifetime());
44+
dataSource.setKeepaliveTime(settings.getMySqlConnectionPoolKeepAlive());
45+
dataSource.setConnectionTimeout(settings.getMySqlConnectionPoolTimeout());
46+
dataSource.setPoolName(DATA_POOL_NAME);
47+
48+
// Set additional connection pool properties
49+
dataSource.setDataSourceProperties(new Properties() {{
50+
put("cachePrepStmts", "true");
51+
put("prepStmtCacheSize", "250");
52+
put("prepStmtCacheSqlLimit", "2048");
53+
put("useServerPrepStmts", "true");
54+
put("useLocalSessionState", "true");
55+
put("useLocalTransactionState", "true");
56+
put("rewriteBatchedStatements", "true");
57+
put("cacheResultSetMetadata", "true");
58+
put("cacheServerConfiguration", "true");
59+
put("elideSetAutoCommits", "true");
60+
put("maintainTimeStats", "false");
61+
}});
62+
}
63+
64+
public MySqlDatabase(@NotNull BattleRoyale plugin) {
65+
super(plugin, "mysql_schema.sql");
66+
}
67+
68+
@Override
69+
public void initialize() throws RuntimeException {
70+
71+
}
72+
73+
@Override
74+
public void close() {
75+
76+
}
77+
}

src/main/java/com/github/elic0de/battleroyale/game/Game.java

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ public void leave(GameUser user) {
7777
bossBar.removePlayer(user);
7878
}
7979

80+
public boolean checkPlayerSize() {
81+
final boolean canStart = getPlayers().size() <= 20;
82+
if (canStart) {
83+
startCountDown();
84+
}
85+
return canStart;
86+
}
87+
8088

8189
public void createTeams(int count) {
8290
int teamSize = Math.max(Math.round(getPlayers().size() / count), 1);
@@ -106,6 +114,35 @@ public void teleportStartLocation(Player player) {
106114
player.teleport(start);
107115
}
108116

117+
public void startCountDown() {
118+
119+
}
120+
121+
public void startGame() {
122+
if (getPhase() instanceof WaitingPhase) {
123+
final WorldBorder border = Bukkit.getWorld("").getWorldBorder();
124+
final Location start = border.getCenter().clone().add((border.getSize() / 2) - 2, 130, (border.getSize() / 2) - 2);
125+
126+
Bukkit.getScheduler().runTask(BattleRoyale.getInstance(), () -> {
127+
getPlayers(GameUser.class).forEach(user -> {
128+
// プレイヤーが所属しているチームを生存しているチームとして登録
129+
// チームに所属していなかったら観戦者とする
130+
getUserTeam(user).ifPresentOrElse(aliveTeams::add, () -> deadPlayers.add(user.getUsername()));
131+
user.clearEffectAndHeal();
132+
133+
user.getPlayer().getInventory().clear();
134+
user.getPlayer().teleport(start);
135+
user.getPlayer().setGameMode(GameMode.SPECTATOR);
136+
137+
// 10秒のクールダウン
138+
user.getPlayer().setCooldown(Material.COMMAND_BLOCK, 10 * 20);
139+
});
140+
nextPhase();
141+
spawnEnderDragon(border.getWorld());
142+
});
143+
}
144+
}
145+
109146
public void startGame(Player player, GameType type, boolean modifier) {
110147
if (getPhase() instanceof WaitingPhase) {
111148
final WorldBorder border = player.getWorld().getWorldBorder();
@@ -133,7 +170,7 @@ public void startGame(Player player, GameType type, boolean modifier) {
133170
user.getPlayer().setCooldown(Material.COMMAND_BLOCK, 10 * 20);
134171
});
135172
nextPhase();
136-
spawnEnderDragon(player);
173+
spawnEnderDragon(player.getWorld());
137174
});
138175
}
139176
}
@@ -144,8 +181,7 @@ public void startBorder() {
144181
sound(Sound.ENTITY_WITHER_SPAWN);
145182
}
146183

147-
public void spawnEnderDragon(Player player) {
148-
final World world = player.getWorld();
184+
public void spawnEnderDragon(World world) {
149185
final WorldBorder border = world.getWorldBorder();
150186
final Location start = border.getCenter().clone().add(border.getSize() / 2, 130, border.getSize() / 2);
151187
final Location end = border.getCenter().clone().subtract(border.getSize() / 2, -130, border.getSize() / 2);
@@ -155,7 +191,7 @@ public void spawnEnderDragon(Player player) {
155191
dragonTrait = new DragonTrait(border);
156192
Bukkit.getScheduler().runTaskTimer(BattleRoyale.getInstance(), task -> {
157193
CitizensNPC dragon = new CitizensNPC(UUID.randomUUID(), 1, "", EntityControllers.createForType(EntityType.ENDER_DRAGON), CitizensAPI.getNPCRegistry());
158-
dragon.spawn(player.getLocation());
194+
dragon.spawn(start);
159195
dragon.addTrait(dragonTrait);
160196
if (dragon.isSpawned()) {
161197
getPlayers().stream().filter(onlineUser -> !deadPlayers.contains(onlineUser.getUsername())).forEach(onlineUser -> dragon.getEntity().addPassenger(onlineUser.getPlayer()));
@@ -205,6 +241,9 @@ public void wonGame() {
205241
broadcast(new MineDown(String.format("%sのチームが勝利しました", team.getDisplayName())));
206242
team.getEntries().forEach(s -> broadcast(new MineDown("&6" + team.getDisplayName())));
207243
title(String.format("%sの勝利", team.getDisplayName()), "");
244+
245+
246+
// todo: ここにfireworkの処理を実装させる
208247
});
209248
endGame();
210249
}
@@ -213,7 +252,8 @@ public void wonGame() {
213252
public void endGame() {
214253
showResult();
215254
sound(Sound.UI_TOAST_CHALLENGE_COMPLETE);
216-
reset();
255+
// 20秒後にリセット
256+
Bukkit.getScheduler().runTaskLater(BattleRoyale.getInstance(), () -> reset(), 20 * 20);
217257
}
218258

219259
// todo

0 commit comments

Comments
 (0)