Skip to content

Commit 790a96b

Browse files
committed
完成
1 parent 9015629 commit 790a96b

File tree

7 files changed

+79
-18
lines changed

7 files changed

+79
-18
lines changed

.github/workflows/main.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: release
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Set up JDK 16
14+
uses: actions/setup-java@v3
15+
with:
16+
distribution: 'temurin'
17+
java-version: '16'
18+
cache: 'maven'
19+
- name: pom.yml バージョン更新
20+
run: mvn versions:set -Dparent.version=release-v${{ github.run_number }}
21+
- name: Mavenを使ってビルド
22+
run: mvn -B package -f pom.xml
23+
- name: original-*.jarを削除
24+
run: rm target/original-*.jar
25+
- name: パッケージをビルドの成果物としてリリース
26+
uses: softprops/action-gh-release@v1
27+
with:
28+
tag_name: release-v${{ github.run_number }}
29+
files: 'target/*.jar'

src/main/java/com/github/elic0de/hungergames/HungerGames.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public void onEnable() {
3535
public void onDisable() {
3636
// Plugin shutdown logic
3737
GameUserManager.getOnlineUsers().forEach(player -> game.leave(player));
38-
Bukkit.getScheduler().cancelTasks(this);
38+
game.reset();
39+
//Bukkit.getScheduler().cancelTasks(this);
3940
}
4041

4142
private void registerCommands() {

src/main/java/com/github/elic0de/hungergames/chest/DeathChest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.github.elic0de.hungergames.user.GameUser;
55
import org.bukkit.Location;
66
import org.bukkit.Material;
7+
import org.bukkit.block.Block;
78
import org.bukkit.entity.Player;
89
import org.bukkit.inventory.ItemStack;
910

@@ -12,18 +13,18 @@
1213

1314
public class DeathChest {
1415

15-
private final Map<Location, ItemStack[]> chestLocations = new HashMap<>();
16+
private final Map<Block, ItemStack[]> chestLocations = new HashMap<>();
1617

1718
public void generateChest(GameUser user) {
1819
final Location chestLocation = user.getPlayer().getLocation();
1920
chestLocation.getWorld().setType(chestLocation, Material.CHEST);
20-
chestLocations.put(chestLocation, user.getPlayer().getInventory().getContents());
21+
chestLocations.put(chestLocation.getBlock(), user.getPlayer().getInventory().getContents());
2122
}
2223

23-
public void openDeathChest(Player player, Location location) {
24-
if (chestLocations.containsKey(location)) {
25-
final ItemStack[] contents = chestLocations.get(location);
26-
new DeathChestMenu(contents).show(player);
24+
public void openDeathChest(Player player, Block block) {
25+
if (chestLocations.containsKey(block)) {
26+
final ItemStack[] contents = chestLocations.get(block);
27+
new DeathChestMenu(contents, player).show();
2728
}
2829
}
2930

src/main/java/com/github/elic0de/hungergames/dragon/DragonTrait.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import com.github.elic0de.hungergames.HungerGames;
44
import net.citizensnpcs.api.trait.Trait;
55
import net.citizensnpcs.npc.CitizensNPC;
6+
import org.bukkit.Bukkit;
67
import org.bukkit.Location;
78
import org.bukkit.WorldBorder;
89
import org.bukkit.scheduler.BukkitRunnable;
10+
import org.bukkit.scheduler.BukkitTask;
911

1012
import java.util.*;
1113
import java.util.concurrent.atomic.AtomicInteger;
@@ -15,6 +17,8 @@ public class DragonTrait extends Trait {
1517
private final Map<Integer, Location> locations = new HashMap<>();
1618
private final AtomicInteger index = new AtomicInteger();
1719

20+
private BukkitTask task;
21+
1822
public DragonTrait(WorldBorder worldBorder) {
1923
super("dragonTrait");
2024
final Location origin = worldBorder.getCenter();
@@ -28,7 +32,8 @@ public DragonTrait(WorldBorder worldBorder) {
2832

2933
@Override
3034
public void run() {
31-
new BukkitRunnable() {
35+
if (task != null) task.cancel();
36+
task = new BukkitRunnable() {
3237
@Override
3338
public void run() {
3439
if (locations.get(index.get()) == null) {
@@ -42,4 +47,9 @@ public void run() {
4247
}
4348
}.runTaskTimer(HungerGames.getInstance(), 0, 20);
4449
}
50+
51+
public void reset() {
52+
npc.destroy();
53+
if (task != null) task.cancel();
54+
}
4555
}

src/main/java/com/github/elic0de/hungergames/game/HungerGame.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.elic0de.eliccommon.game.AbstractGame;
44
import com.github.elic0de.eliccommon.game.phase.Phase;
5+
import com.github.elic0de.hungergames.HungerGames;
56
import com.github.elic0de.hungergames.chest.DeathChest;
67
import com.github.elic0de.hungergames.dragon.DragonTrait;
78
import com.github.elic0de.hungergames.game.phase.InGamePhase;
@@ -40,6 +41,8 @@ public class HungerGame extends AbstractGame {
4041
@Getter
4142
private final Set<String> deadPlayers = new HashSet<>();
4243

44+
private DragonTrait dragonTrait;
45+
4346
public HungerGame() {
4447
scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
4548
border = new GameBorder(this);
@@ -71,14 +74,21 @@ public void spawnEnderDragon(World world) {
7174
final WorldBorder border = world.getWorldBorder();
7275
final Location start = border.getCenter().clone().add(border.getSize() / 2, 130, border.getSize() / 2);
7376
getPlayers().forEach(onlineUser -> {
74-
onlineUser.getPlayer().setGameMode(GameMode.SPECTATOR);
7577
onlineUser.getPlayer().teleport(start);
78+
onlineUser.getPlayer().setGameMode(GameMode.SPECTATOR);
7679
});
7780

81+
dragonTrait = new DragonTrait(border);
82+
7883
CitizensNPC dragon = new CitizensNPC(UUID.randomUUID(), 1, "", EntityControllers.createForType(EntityType.ENDER_DRAGON), CitizensAPI.getNPCRegistry());
7984
dragon.spawn(start);
80-
dragon.addTrait(new DragonTrait(border));
81-
getPlayers().forEach(onlineUser -> dragon.getEntity().addPassenger(onlineUser.getPlayer()));
85+
dragon.addTrait(dragonTrait);
86+
Bukkit.getScheduler().runTask(HungerGames.getInstance(), () -> {
87+
getPlayers().forEach(onlineUser -> {
88+
89+
dragon.getEntity().addPassenger(onlineUser.getPlayer());
90+
});
91+
});
8292
}
8393

8494
public void dismountWithTeam(GameUser user) {
@@ -118,6 +128,7 @@ public void wonGame() {
118128
@Override
119129
public void reset() {
120130
border.reset();
131+
if (dragonTrait != null) dragonTrait.reset();
121132
}
122133

123134
public void sendMessageSpectators(GameUser user, String message) {

src/main/java/com/github/elic0de/hungergames/listener/EventListener.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private void onDismount(EntityDismountEvent event) {
5555
if (event.getDismounted() instanceof EnderDragon) {
5656
game.dismountWithTeam(GameUserManager.getGameUser(player));
5757
}
58-
player.getInventory().addItem(ItemBuilder.of(Material.FIREWORK_STAR).build());
58+
player.getInventory().addItem(ItemBuilder.of(Material.FIREWORK_ROCKET).build());
5959
player.getInventory().setChestplate(ItemBuilder.of(Material.ELYTRA).build());
6060
player.setGliding(true);
6161
}
@@ -77,7 +77,9 @@ private void onMove(PlayerMoveEvent event) {
7777
@EventHandler
7878
private void onDamage(EntityDamageEvent event) {
7979
if (event.getEntity() instanceof Player) {
80-
if (event.getCause() == EntityDamageEvent.DamageCause.FALL) event.setCancelled(true);
80+
switch (event.getCause()) {
81+
case FALL, FLY_INTO_WALL -> event.setCancelled(true);
82+
}
8183
}
8284
}
8385

@@ -86,7 +88,7 @@ private void onInteract(PlayerInteractEvent event) {
8688
final Block block = event.getClickedBlock();
8789
if (block == null) return;
8890
if (block.getType() == Material.CHEST && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
89-
game.getDeathChest().openDeathChest(event.getPlayer(), block.getLocation());
91+
game.getDeathChest().openDeathChest(event.getPlayer(), block);
9092
}
9193
}
9294

src/main/java/com/github/elic0de/hungergames/menu/DeathChestMenu.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class DeathChestMenu {
1313

1414
private final InventoryGui menu;
1515

16+
private final Player player;
17+
1618
private static final String[] MENU_LAYOUT = {
1719
"ppppppppp",
1820
"ppppppppp",
@@ -21,15 +23,20 @@ public class DeathChestMenu {
2123
"ppppppppp",
2224
"ppppppppp"
2325
};
24-
public DeathChestMenu(ItemStack[] contents) {
26+
public DeathChestMenu(ItemStack[] contents, Player player) {
27+
this.player = player;
2528
this.menu = new InventoryGui(HungerGames.getInstance(), "DeathChest", MENU_LAYOUT);
26-
Inventory inv = Bukkit.createInventory(null, InventoryType.CHEST);
29+
Inventory inv = Bukkit.createInventory(null, 54);
2730
inv.setContents(contents);
2831
menu.addElement(new GuiStorageElement('p', inv));
2932
menu.setCloseAction(close -> false);
33+
3034
}
3135

32-
public void show(Player player) {
33-
menu.show(player);
36+
public void show() {
37+
Bukkit.getScheduler().runTask(HungerGames.getInstance(), () -> {
38+
player.closeInventory();
39+
menu.show(player);
40+
});
3441
}
3542
}

0 commit comments

Comments
 (0)