Skip to content

Commit

Permalink
試合中にFキーを押して武器を追加で持てるバグを修正+キルログにアイテム詳細を表示
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisa9006 committed Aug 23, 2024
1 parent 2d611bf commit a5d7b77
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>net.azisaba</groupId>
<artifactId>LeonGunWar</artifactId>
<version>2.0.0</version>
<version>2.0.2</version>

<name>${project.artifactId}</name>
<description>A core plugin in Azisaba LeonGunWar</description>
Expand Down
53 changes: 46 additions & 7 deletions src/main/java/net/azisaba/lgw/core/listeners/DamageListener.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package net.azisaba.lgw.core.listeners;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import net.azisaba.lgw.core.events.PlayerKillEvent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentBuilder;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
Expand Down Expand Up @@ -207,6 +213,7 @@ public void deathMessageChanger(PlayerDeathEvent e) {
// DisplayNameを取得
itemName = crackshot.getString(nodes + ".Item_Information.Item_Name");


// DisplayNameがnullの場合は普通にアイテム名を取得
if ( itemName == null ) {
itemName = item.getItemMeta().getDisplayName();
Expand All @@ -220,15 +227,47 @@ public void deathMessageChanger(PlayerDeathEvent e) {
// メッセージ削除
e.deathMessage(null);
// メッセージ作成
String msg = Chat.f("{0}&r{1} &7━━━ [ &r{2} &7] ━━━> &r{3}", LeonGunWar.GAME_PREFIX, killer.getPlayerListName(),
itemName,
p.getPlayerListName());
// String msg = Chat.f("{0}&r{1} &7━━━ [ &r{2} &7] ━━━> &r{3}", LeonGunWar.GAME_PREFIX, killer.getPlayerListName(),
// itemName,
// p.getPlayerListName());

TextComponent msg2 =Component.text()
.append(Component.text(LeonGunWar.GAME_PREFIX))
.append(Component.text(killer.getPlayerListName()))
.append(Component.text("━━━ [ ").color(NamedTextColor.GRAY))
.append(Component.text(itemName))
.append(Component.text("] ━━━>").color(NamedTextColor.GRAY))
.append(Component.text(p.getPlayerListName()))
.build();


// LoreをComponentリストとして取得
List<Component> loreComponents = p.getKiller().getInventory().getItemInMainHand().lore();

// Loreを一つのComponentにまとめる
TextComponent.Builder loreTextBuilder = Component.text();
if (loreComponents != null) {
for (Component loreLine : loreComponents) {
loreTextBuilder.append(loreLine).append(Component.text("\n"));
}
}
// ホバーイベントの作成(Loreを含む)
HoverEvent<Component> hoverEvent = HoverEvent.showText(
Component.text(itemName, NamedTextColor.AQUA)
.append(Component.text("\n"))
.append(loreTextBuilder.build())
);

// ホバーイベントをメインメッセージに追加
TextComponent messageWithTooltip = msg2.hoverEvent(hoverEvent);

// メッセージ送信
p.getWorld().getPlayers().forEach(player -> player.sendMessage(messageWithTooltip));

// コンソールに出力
Bukkit.getConsoleSender().sendMessage(messageWithTooltip);

// メッセージ送信
p.getWorld().getPlayers().forEach(player -> player.sendMessage(msg));

// コンソールに出力
Bukkit.getConsoleSender().sendMessage(msg);
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
Expand All @@ -31,6 +32,13 @@ public AfkKickEntryListener() {
public void onMove(PlayerMoveEvent e) {
lastMoved.put(e.getPlayer(), System.currentTimeMillis());
}
/**
* 銃を撃ったときも値を設定
*/
@EventHandler(ignoreCancelled = true)
public void onShot(PlayerInteractEvent e) {
lastMoved.put(e.getPlayer(), System.currentTimeMillis());
}

/**
* 参加したときも値を設定
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
Expand Down Expand Up @@ -55,6 +56,40 @@ public static ItemStack[] getHotbar(PlayerInventory inventory) {
private final CSDirector cs = (CSDirector) Bukkit.getPluginManager().getPlugin("CrackShot");
private final CSUtility csUtil = new CSUtility();

@EventHandler
public void onSwapHand(PlayerSwapHandItemsEvent event) {
Inventory inventory = event.getPlayer().getInventory();

if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
return;
}

if(LeonGunWar.getPlugin().getManager().getCurrentGameMap() != null) {
if (LeonGunWar.getPlugin().getManager().getCurrentGameMap().getSpawnPoint(LeonGunWar.getPlugin().getManager().getBattleTeam((Player) event.getPlayer())) != null) {
Location spawnPoint = LeonGunWar.getPlugin().getManager().getCurrentGameMap().getSpawnPoint(LeonGunWar.getPlugin().getManager().getBattleTeam((Player) event.getPlayer()));
if (spawnPoint.distance(event.getPlayer().getLocation()) <= 10) {
return;
}
}
}


Player player = event.getPlayer();

if (!LeonGunWar.getPlugin().getManager().isPlayerMatching(player)) {
return;
}

if (!LeonGunWar.getPlugin().getManager().getItemChangeValidator()
.isAllowedToChangeItem(player)) {
event.setCancelled(true);
return;
}

ItemStack[] befores = getHotbar((PlayerInventory) inventory);
hotbars.putIfAbsent(player, befores);
}

@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
Inventory inventory = event.getClickedInventory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
Expand All @@ -15,10 +16,10 @@
public class DisableOffhandListener implements Listener {

// Fキーでのオフハンド切り替えを無効化
@EventHandler
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent e) {
e.setCancelled(true);
}
//@EventHandler(priority = EventPriority.LOWEST)
//public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent e) {
// e.setCancelled(true);
//}

// インベントリーを閉じた際にオフハンドにアイテムがある場合は移動するかドロップ
@EventHandler
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/azisaba/lgw/core/util/MatchMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum MatchMode {
Chat.f("&6上限なしチームデスマッチ"),
Chat.f("&6TDM-NOLIMIT"),
Chat.f("&7終了時に &cキル数が多いチーム &7が勝利"),
Duration.ofMinutes(15),
Duration.ofMinutes(10),
Arrays.asList("tdmn", "nolimit", "no-limit", "teamdeathmatchnolimit", "tdm-nolimit", "tdm-no-limit", "team-no-limit", "team-nolimit")),

LEADER_DEATH_MATCH(
Expand Down

0 comments on commit a5d7b77

Please sign in to comment.