Skip to content

Commit 2b34937

Browse files
committed
先方のプラグイン完成したのでこちらに移る
1 parent 8ab1ddf commit 2b34937

File tree

12 files changed

+302
-4
lines changed

12 files changed

+302
-4
lines changed

pom.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
</properties>
1818

1919
<build>
20+
<finalName>${project.name}</finalName>
2021
<plugins>
2122
<plugin>
2223
<groupId>org.apache.maven.plugins</groupId>
@@ -30,7 +31,15 @@
3031
<plugin>
3132
<groupId>org.apache.maven.plugins</groupId>
3233
<artifactId>maven-shade-plugin</artifactId>
33-
<version>3.2.4</version>
34+
<version>3.4.0</version>
35+
<configuration>
36+
<relocations>
37+
<relocation>
38+
<pattern>com.github.elic0de.eliccommon</pattern>
39+
<shadedPattern>com.github.elic0de.setsubun.commons</shadedPattern>
40+
</relocation>
41+
</relocations>
42+
</configuration>
3443
<executions>
3544
<execution>
3645
<phase>package</phase>
@@ -61,6 +70,10 @@
6170
<id>sonatype</id>
6271
<url>https://oss.sonatype.org/content/groups/public/</url>
6372
</repository>
73+
<repository>
74+
<id>jitpack.io</id>
75+
<url>https://jitpack.io</url>
76+
</repository>
6477
</repositories>
6578

6679
<dependencies>
@@ -70,5 +83,11 @@
7083
<version>1.19.2-R0.1-SNAPSHOT</version>
7184
<scope>provided</scope>
7285
</dependency>
86+
<dependency>
87+
<groupId>com.github.Elic0de</groupId>
88+
<artifactId>ElicCommon</artifactId>
89+
<version>d3c6df5da9</version>
90+
<scope>compile</scope>
91+
</dependency>
7392
</dependencies>
7493
</project>
Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
11
package com.github.elic0de.hungergames;
22

3-
import org.bukkit.plugin.java.JavaPlugin;
3+
import com.github.elic0de.eliccommon.plugin.AbstractPlugin;
4+
import com.github.elic0de.hungergames.game.HungerGame;
45

5-
public final class HungerGames extends JavaPlugin {
6+
public final class HungerGames extends AbstractPlugin {
7+
8+
private static HungerGames instance;
9+
10+
private HungerGame game;
11+
12+
@Override
13+
public void onLoad() {
14+
super.onLoad();
15+
instance = this;
16+
}
617

718
@Override
819
public void onEnable() {
920
// Plugin startup logic
10-
21+
game = new HungerGame();
1122
}
1223

1324
@Override
1425
public void onDisable() {
1526
// Plugin shutdown logic
1627
}
28+
29+
public HungerGame getGame() {
30+
return game;
31+
}
32+
33+
public static HungerGames getInstance() {
34+
return instance;
35+
}
1736
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.github.elic0de.hungergames.border;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.WorldBorder;
5+
6+
public class GameBorder {
7+
8+
private final WorldBorder border = Bukkit.getWorlds().get(0).getWorldBorder();
9+
10+
private final double MAX_BORDER_SIZE = 500;
11+
12+
public GameBorder() {
13+
border.setDamageBuffer(1);
14+
border.setSize(MAX_BORDER_SIZE);
15+
}
16+
17+
public void start() {
18+
reset();
19+
double MIN_BORDER_SIZE = 16;
20+
border.setSize(MIN_BORDER_SIZE, 900);
21+
}
22+
23+
public void stop() {
24+
border.setSize(border.getSize());
25+
}
26+
27+
public void reset() {
28+
border.setSize(MAX_BORDER_SIZE);
29+
}
30+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.github.elic0de.hungergames.game;
2+
3+
import com.github.elic0de.eliccommon.game.AbstractGame;
4+
import com.github.elic0de.eliccommon.game.phase.Phase;
5+
import com.github.elic0de.hungergames.user.GameUser;
6+
import com.github.elic0de.hungergames.user.GameUserManager;
7+
import de.themoep.minedown.MineDown;
8+
import org.bukkit.Bukkit;
9+
import org.bukkit.GameMode;
10+
import org.bukkit.scoreboard.Scoreboard;
11+
import org.bukkit.scoreboard.Team;
12+
import org.jetbrains.annotations.NotNull;
13+
14+
import java.util.*;
15+
import java.util.stream.Collectors;
16+
17+
public class HungerGame extends AbstractGame {
18+
19+
private final Scoreboard scoreboard;
20+
21+
private final Set<Team> deadTeams = new HashSet<>();
22+
private final Set<String> deadPlayers = new HashSet<>();
23+
24+
public HungerGame() {
25+
scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
26+
}
27+
28+
public void onDeath(GameUser user) {
29+
if (isSpectator(user)) return;
30+
31+
deadPlayers.add(user.getUsername());
32+
if (deadPlayers.size() == 10) {
33+
broadcast(new MineDown("残りプレイヤー10人"));
34+
}
35+
36+
getUserTeam(user).ifPresent(team -> {
37+
if (checkTeamDead(user)) deadTeams.add(team);
38+
});
39+
40+
if (scoreboard.getTeams().size() == deadTeams.size() + 1) {
41+
wonGame();
42+
}
43+
44+
user.getPlayer().setGameMode(GameMode.SPECTATOR);
45+
user.getPlayer().getWorld().strikeLightningEffect(user.getPlayer().getLocation());
46+
}
47+
48+
public void wonGame() {
49+
scoreboard.getTeams().stream().filter(team -> !deadTeams.contains(team)).findAny().ifPresent(team -> {
50+
broadcast(new MineDown(String.format("%sのチームが勝利しました", team.getName())));
51+
});
52+
}
53+
54+
public void sendMessageSpectators(GameUser user, String message) {
55+
getPlayers(GameUser.class).forEach(onlineUser -> {
56+
if (isSpectator(onlineUser)) onlineUser.sendMessage(new MineDown(String.format("%s: %s", user.getUsername(), message)));
57+
});
58+
}
59+
60+
public void sendMessageOwnTeam(GameUser user, String message) {
61+
getTeamUsers(user).forEach(player -> player.sendMessage(new MineDown(String.format("%s: %s", user.getUsername(), message))));
62+
}
63+
64+
public boolean isSpectator(GameUser user) {
65+
return deadPlayers.contains(user.getUsername());
66+
}
67+
68+
public boolean checkTeamDead(GameUser user) {
69+
if (getUserTeam(user).isPresent()) {
70+
final Team team = getUserTeam(user).get();
71+
for (String name : team.getEntries()) {
72+
if (deadPlayers.contains(name)) continue;
73+
return false;
74+
}
75+
}
76+
return true;
77+
}
78+
79+
private Optional<Team> getUserTeam(GameUser user) {
80+
final Team team = scoreboard.getEntryTeam(user.getUsername());
81+
return Optional.ofNullable(team);
82+
}
83+
84+
private Set<GameUser> getTeamUsers(GameUser user) {
85+
final Team team = scoreboard.getEntryTeam(user.getUsername());
86+
if (team == null) return new HashSet<>();
87+
return team.getEntries().stream().map(Bukkit::getPlayer).filter(Objects::nonNull).map(GameUserManager::getGameUser).collect(Collectors.toSet());
88+
}
89+
90+
@Override
91+
public @NotNull Phase[] getPhases() {
92+
return new Phase[0];
93+
}
94+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.github.elic0de.hungergames.game.phase;
2+
3+
public class EndGamePhase {
4+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.github.elic0de.hungergames.game.phase;
2+
3+
import com.github.elic0de.eliccommon.game.phase.Phase;
4+
import com.github.elic0de.eliccommon.user.OnlineUser;
5+
6+
public class InGamePhase extends Phase {
7+
8+
public InGamePhase(long startDelay, long endDelay) {
9+
super(startDelay, endDelay);
10+
}
11+
12+
@Override
13+
public void start() {
14+
15+
}
16+
17+
@Override
18+
public void update() {
19+
20+
}
21+
22+
@Override
23+
public void end() {
24+
25+
}
26+
27+
@Override
28+
public void join(OnlineUser player) {
29+
30+
}
31+
32+
@Override
33+
public void leave(OnlineUser player) {
34+
35+
}
36+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.github.elic0de.hungergames.game.phase;
2+
3+
public class ResetPhase {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.github.elic0de.hungergames.game.phase;
2+
3+
public class WaitingPhase {
4+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.github.elic0de.hungergames.listener;
2+
3+
import com.github.elic0de.hungergames.HungerGames;
4+
import com.github.elic0de.hungergames.game.HungerGame;
5+
import com.github.elic0de.hungergames.game.phase.InGamePhase;
6+
import com.github.elic0de.hungergames.user.GameUser;
7+
import com.github.elic0de.hungergames.user.GameUserManager;
8+
import org.bukkit.event.EventHandler;
9+
import org.bukkit.event.Listener;
10+
import org.bukkit.event.entity.PlayerDeathEvent;
11+
import org.bukkit.event.player.AsyncPlayerChatEvent;
12+
13+
public class EventListener implements Listener {
14+
15+
private final HungerGame game = HungerGames.getInstance().getGame();
16+
17+
@EventHandler
18+
private void onDeath(PlayerDeathEvent event) {
19+
final GameUser user = GameUserManager.getGameUser(event.getEntity());
20+
game.onDeath(user);
21+
}
22+
23+
@EventHandler
24+
private void onTeamChat(AsyncPlayerChatEvent event) {
25+
if (game.getPhase() instanceof InGamePhase) {
26+
final GameUser sender = GameUserManager.getGameUser(event.getPlayer());
27+
if (game.isSpectator(sender)) {
28+
game.sendMessageSpectators(sender, event.getMessage());
29+
return;
30+
}
31+
game.sendMessageOwnTeam(sender, event.getMessage());
32+
}
33+
}
34+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.github.elic0de.hungergames.menu;
2+
3+
public class DeathChestMenu {
4+
}

0 commit comments

Comments
 (0)