From 6a3435a852473c5dbeb57072ebe3cf9df14e96d6 Mon Sep 17 00:00:00 2001
From: yaohunya <31456652@qq.com>
Date: Sat, 10 Aug 2024 15:36:50 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=89=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 36 +++++++++++++++
.../java/com/yaohun/enderdragonWars/Main.java | 27 ++++++++++++
.../yaohun/enderdragonWars/data/GiftData.java | 41 +++++++++++++++++
.../enderdragonWars/manage/GameManage.java | 44 +++++++++++++++++++
.../yaohun/enderdragonWars/util/GameUtil.java | 37 ++++++++++++++++
src/main/resources/plugin.yml | 5 +++
6 files changed, 190 insertions(+)
create mode 100644 pom.xml
create mode 100644 src/main/java/com/yaohun/enderdragonWars/Main.java
create mode 100644 src/main/java/com/yaohun/enderdragonWars/data/GiftData.java
create mode 100644 src/main/java/com/yaohun/enderdragonWars/manage/GameManage.java
create mode 100644 src/main/java/com/yaohun/enderdragonWars/util/GameUtil.java
create mode 100644 src/main/resources/plugin.yml
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..3bf913e
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,36 @@
+
+
+ 4.0.0
+
+ org.example
+ EnderDragonWars
+ 1.0-SNAPSHOT
+
+
+ 17
+ 17
+
+
+
+
+ papermc-repo
+ https://repo.papermc.io/repository/maven-public/
+
+
+ sonatype
+ https://oss.sonatype.org/content/groups/public/
+
+
+
+
+
+ io.papermc.paper
+ paper-api
+ 1.20.6-R0.1-SNAPSHOT
+ provided
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/yaohun/enderdragonWars/Main.java b/src/main/java/com/yaohun/enderdragonWars/Main.java
new file mode 100644
index 0000000..1d117b3
--- /dev/null
+++ b/src/main/java/com/yaohun/enderdragonWars/Main.java
@@ -0,0 +1,27 @@
+package com.yaohun.enderdragonWars;
+
+import com.yaohun.enderdragonWars.game.Game;
+import com.yaohun.enderdragonWars.manage.GameManage;
+import com.yaohun.enderdragonWars.manage.GiftEffectManager;
+import org.bukkit.plugin.java.JavaPlugin;
+
+public class Main extends JavaPlugin {
+
+ public static Main plugin;
+ public static GameManage gameManage;
+ public static Game game;
+
+ @Override
+ public void onEnable() {
+ plugin = this;
+ GiftEffectManager.registerAll();
+ gameManage = new GameManage();
+ game = new Game();
+ }
+
+
+ @Override
+ public void onDisable() {
+ GiftEffectManager.stopQueue();
+ }
+}
diff --git a/src/main/java/com/yaohun/enderdragonWars/data/GiftData.java b/src/main/java/com/yaohun/enderdragonWars/data/GiftData.java
new file mode 100644
index 0000000..4bf85dd
--- /dev/null
+++ b/src/main/java/com/yaohun/enderdragonWars/data/GiftData.java
@@ -0,0 +1,41 @@
+package com.yaohun.enderdragonWars.data;
+
+import com.yaohun.enderdragonWars.util.GameUtil;
+import org.bukkit.Bukkit;
+import org.bukkit.configuration.file.FileConfiguration;
+
+public class GiftData {
+ private String giftName; // 礼物名
+ private String event; // 效果名
+ private int minutes; // 加播或减播
+ private String sounds; // 自定义音效
+
+ public GiftData(String giftName, FileConfiguration yml) {
+ this.giftName = giftName;
+ String str = "礼物设置." + giftName + ".";
+ if (yml.getString(str + "声音") != null) {
+ this.sounds = yml.getString(str + "声音");
+ }
+ this.event = yml.getString(str + "效果");
+ this.minutes = yml.getInt(str + "加播");
+ if (this.minutes >= 1) {
+ Bukkit.getConsoleSender().sendMessage("事件: " + this.event + " 条件: " + giftName + " 加播: +" + minutes + "分钟");
+ } else {
+ Bukkit.getConsoleSender().sendMessage("事件: " + this.event + " 条件: " + giftName + " 减播: -" + minutes + "分钟");
+ }
+ }
+
+ public String getGiftName() {
+ return giftName;
+ }
+
+ public String getEvent() {
+ return event;
+ }
+
+ public void OutPlaySoundsEvent() {
+ if(!sounds.equalsIgnoreCase("NULL")) {
+ GameUtil.SendAllSounds(sounds);
+ }
+ }
+}
diff --git a/src/main/java/com/yaohun/enderdragonWars/manage/GameManage.java b/src/main/java/com/yaohun/enderdragonWars/manage/GameManage.java
new file mode 100644
index 0000000..ba3d53c
--- /dev/null
+++ b/src/main/java/com/yaohun/enderdragonWars/manage/GameManage.java
@@ -0,0 +1,44 @@
+package com.yaohun.enderdragonWars.manage;
+
+import com.yaohun.enderdragonWars.data.GiftData;
+import org.bukkit.Bukkit;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+
+public class GameManage {
+
+ private HashMap giftDataMap = new HashMap<>();
+ public GameManage(){
+ loadGiftData();
+ }
+
+ public void loadGiftData(){
+ File file = new File("./plugins/游戏设置","礼物设置.yml");
+ FileConfiguration yml = YamlConfiguration.loadConfiguration(file);
+ Bukkit.getConsoleSender().sendMessage("[日志 - 末影龙挑战] 事件注册:");
+ ConfigurationSection section = yml.getConfigurationSection("礼物设置");
+ if(section == null){
+ System.out.println("[错误 - 游戏] 礼物设置错误,请检查文件.");
+ return;
+ }
+ for (String giftName : section.getKeys(false)){
+ giftDataMap.put(giftName,new GiftData(giftName,yml));
+ }
+ }
+
+ public HashMap getGiftDataMap() {
+ return giftDataMap;
+ }
+
+ public GiftData getGiftData(String giftName){
+ if(getGiftDataMap().get(giftName) == null){
+ return null;
+ }
+ return getGiftDataMap().get(giftName);
+ }
+}
diff --git a/src/main/java/com/yaohun/enderdragonWars/util/GameUtil.java b/src/main/java/com/yaohun/enderdragonWars/util/GameUtil.java
new file mode 100644
index 0000000..819fb16
--- /dev/null
+++ b/src/main/java/com/yaohun/enderdragonWars/util/GameUtil.java
@@ -0,0 +1,37 @@
+package com.yaohun.enderdragonWars.util;
+
+
+import org.bukkit.*;
+import org.bukkit.block.Block;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Pig;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+
+public class GameUtil {
+
+ public static String HideName(String audience){
+ if(audience.length() <= 2){
+ return "**";
+ }
+ // 获取第一个和第二个字符
+ char firstChar = audience.charAt(0);
+ char lastChar = audience.charAt(audience.length() - 1);
+ // 构建屏蔽后的字符串
+ StringBuilder maskedString = new StringBuilder();
+ for (int i = 1; i < audience.length() - 1; i++) {
+ maskedString.append('*');
+ }
+ return String.valueOf(firstChar) + maskedString + lastChar;
+ }
+
+ public static void SendAllSounds(String sound){
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ if (!sound.contains("_")) {
+ player.playSound(player.getLocation(), sound, 0.5F, 1);
+ }
+ }
+ }
+}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
new file mode 100644
index 0000000..abf881b
--- /dev/null
+++ b/src/main/resources/plugin.yml
@@ -0,0 +1,5 @@
+name: EnderDragonWars
+main:
+version: 1.0
+commands:
+ game:
\ No newline at end of file