diff --git a/pom.xml b/pom.xml
index 8788353..70aa153 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,8 +23,8 @@
maven-compiler-plugin
3.8.1
-
- ${java.version}
+
+ 16
@@ -63,7 +63,11 @@
public
- http://111.230.48.153:18081/repository/public/
+ https://repo.aurora-pixels.com/repository/public/
+
+
+ public-rpg
+ https://repo.aurora-pixels.com/repository/public-rpg/
@@ -74,5 +78,11 @@
1.18.2-R0.1-SNAPSHOT
provided
+
+ com.sk89q
+ fastasyncworldedit
+ 2.9.1
+ 669
+
diff --git a/src/main/java/com/io/yutian/colorblindwar/ColorblindWar.java b/src/main/java/com/io/yutian/colorblindwar/ColorblindWar.java
index 4fdeced..8f5b340 100644
--- a/src/main/java/com/io/yutian/colorblindwar/ColorblindWar.java
+++ b/src/main/java/com/io/yutian/colorblindwar/ColorblindWar.java
@@ -3,12 +3,16 @@ package com.io.yutian.colorblindwar;
import com.io.yutian.colorblindwar.game.DirectionPoint;
import com.io.yutian.colorblindwar.game.Game;
import com.io.yutian.colorblindwar.listener.PlayerListener;
+import com.io.yutian.colorblindwar.live.GiftQueue;
+import com.io.yutian.colorblindwar.manager.GiftEffectManager;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
+import java.util.Map;
+
public final class ColorblindWar extends JavaPlugin {
private static ColorblindWar instance;
@@ -17,10 +21,20 @@ public final class ColorblindWar extends JavaPlugin {
@Override
public void onEnable() {
instance = this;
+
+ GiftEffectManager.registerAll();
+
game = new Game();
Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
}
+ @Override
+ public void onDisable() {
+ if (game.isStarted()) {
+ game.stop(false);
+ }
+ }
+
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 0) {
@@ -62,6 +76,24 @@ public final class ColorblindWar extends JavaPlugin {
} else if (subCommand.equalsIgnoreCase("reload")) {
game.reload();
sender.sendMessage("重载成功");
+ } else if (subCommand.equalsIgnoreCase("test")) {
+ if (!(sender instanceof Player)) {
+ return true;
+ }
+ String s1 = args[1];
+ Player player = (Player) sender;
+ if (s1.equalsIgnoreCase("add")) {
+ GiftEffectManager.addGiftEffect(player.getName(), "致盲");
+ player.sendMessage("add effect success");
+ } else if (s1.equalsIgnoreCase("list")) {
+ player.sendMessage("effect list:");
+ for (Map.Entry entry : GiftEffectManager.getGiftQueues().entrySet()) {
+ String type = entry.getKey();
+ GiftQueue giftQueue = entry.getValue();
+ player.sendMessage(type+":");
+ player.sendMessage(" "+giftQueue.getEffectQueue().toString());
+ }
+ }
}
}
return true;
diff --git a/src/main/java/com/io/yutian/colorblindwar/effect/EffectTime.java b/src/main/java/com/io/yutian/colorblindwar/effect/EffectTime.java
deleted file mode 100644
index d59d68e..0000000
--- a/src/main/java/com/io/yutian/colorblindwar/effect/EffectTime.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.io.yutian.colorblindwar.effect;
-
-public class EffectTime {
-}
diff --git a/src/main/java/com/io/yutian/colorblindwar/game/Game.java b/src/main/java/com/io/yutian/colorblindwar/game/Game.java
index 57d9f90..d0748e7 100644
--- a/src/main/java/com/io/yutian/colorblindwar/game/Game.java
+++ b/src/main/java/com/io/yutian/colorblindwar/game/Game.java
@@ -34,7 +34,6 @@ public class Game {
private static final List MATERIAL_LIST = Arrays.asList(Material.WHITE_WOOL, Material.BLACK_WOOL, Material.BROWN_WOOL, Material.BLUE_WOOL, Material.GREEN_WOOL, Material.RED_WOOL, Material.YELLOW_WOOL, Material.PURPLE_WOOL, Material.ORANGE_WOOL, Material.PINK_WOOL, Material.LIGHT_BLUE_WOOL, Material.LIME_WOOL);
-
private World world;
private DirectionPoint spawnPoint;
@@ -146,6 +145,8 @@ public class Game {
for (Entity entity : entities) {
entity.remove();
}
+
+ spawnBuild();
this.bossBar1.removeAll();
this.bossBar2.removeAll();
this.bossBar3.removeAll();
@@ -341,6 +342,10 @@ public class Game {
return started;
}
+ public Player getPlayer() {
+ return player;
+ }
+
public World getWorld() {
return world;
}
diff --git a/src/main/java/com/io/yutian/colorblindwar/listener/PlayerListener.java b/src/main/java/com/io/yutian/colorblindwar/listener/PlayerListener.java
index b2e21ae..2e4d97a 100644
--- a/src/main/java/com/io/yutian/colorblindwar/listener/PlayerListener.java
+++ b/src/main/java/com/io/yutian/colorblindwar/listener/PlayerListener.java
@@ -1,17 +1,45 @@
package com.io.yutian.colorblindwar.listener;
import com.io.yutian.colorblindwar.ColorblindWar;
+import com.io.yutian.colorblindwar.game.Game;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
+import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
public class PlayerListener implements Listener {
+ @EventHandler
+ public void onPlayerRespawn(PlayerRespawnEvent event) {
+ if (ColorblindWar.getGame().isStarted()) {
+ Game game = ColorblindWar.getGame();
+ event.setRespawnLocation(game.getSpawnPoint().toLocation(game.getWorld()));
+ }
+ }
+
+ @EventHandler
+ public void onPlayerDamage(EntityDamageEvent event) {
+ Entity entity = event.getEntity();
+ Game game = ColorblindWar.getGame();
+ if (entity instanceof Player player) {
+ if (game.isStarted()) {
+ EntityDamageEvent.DamageCause damageCause = event.getCause();
+ if (damageCause == EntityDamageEvent.DamageCause.VOID) {
+ entity.teleport(game.getSpawnPoint().toLocation(game.getWorld()));
+ event.setCancelled(true);
+ }
+ }
+ }
+ }
+
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
if (ColorblindWar.getGame().isStarted()) {
diff --git a/src/main/java/com/io/yutian/colorblindwar/live/GiftEffect.java b/src/main/java/com/io/yutian/colorblindwar/live/GiftEffect.java
new file mode 100644
index 0000000..8775e4c
--- /dev/null
+++ b/src/main/java/com/io/yutian/colorblindwar/live/GiftEffect.java
@@ -0,0 +1,23 @@
+package com.io.yutian.colorblindwar.live;
+
+import com.io.yutian.colorblindwar.game.Game;
+
+public abstract class GiftEffect {
+
+ private String audience;
+
+ public GiftEffect(String audience) {
+ this.audience = audience;
+ }
+
+ public String getAudience() {
+ return audience;
+ }
+
+ public abstract void apply(Game game);
+
+ public int getQueueTime() {
+ return 20;
+ }
+
+}
diff --git a/src/main/java/com/io/yutian/colorblindwar/live/GiftQueue.java b/src/main/java/com/io/yutian/colorblindwar/live/GiftQueue.java
new file mode 100644
index 0000000..91bdf7d
--- /dev/null
+++ b/src/main/java/com/io/yutian/colorblindwar/live/GiftQueue.java
@@ -0,0 +1,54 @@
+package com.io.yutian.colorblindwar.live;
+
+import com.io.yutian.colorblindwar.ColorblindWar;
+import com.io.yutian.colorblindwar.game.Game;
+import org.bukkit.Bukkit;
+import org.bukkit.scheduler.BukkitTask;
+
+import java.util.LinkedList;
+import java.util.Queue;
+
+public class GiftQueue {
+
+ private Queue effectQueue = new LinkedList<>();
+
+ private BukkitTask task;
+
+ public GiftQueue(int waitTime) {
+ task = Bukkit.getScheduler().runTaskTimer(ColorblindWar.inst(), new Runnable() {
+ private int timer = 0;
+ private boolean running = false;
+ @Override
+ public void run() {
+ timer++;
+ if (!running) {
+ timer = waitTime;
+ running = true;
+ }
+ if (timer >= waitTime) {
+ timer = 0;
+ if (effectQueue.isEmpty()) {
+ running = false;
+ return;
+ }
+ Game game = ColorblindWar.getGame();
+ GiftEffect effect = effectQueue.poll();
+ effect.apply(game);
+ }
+ }
+ }, 0L, 1L);
+ }
+
+ public void addEffect(GiftEffect effect) {
+ effectQueue.add(effect);
+ }
+
+ public Queue getEffectQueue() {
+ return effectQueue;
+ }
+
+ public BukkitTask getTask() {
+ return task;
+ }
+
+}
diff --git a/src/main/java/com/io/yutian/colorblindwar/liveevent/GiftEventHandler.java b/src/main/java/com/io/yutian/colorblindwar/liveevent/GiftEventHandler.java
deleted file mode 100644
index 1bbac7b..0000000
--- a/src/main/java/com/io/yutian/colorblindwar/liveevent/GiftEventHandler.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.io.yutian.colorblindwar.liveevent;
-
-import com.io.yutian.colorblindwar.ColorblindWar;
-import com.io.yutian.colorblindwar.game.Game;
-import com.io.yutian.colorblindwar.util.GameUtil;
-import org.bukkit.entity.Player;
-
-public class GiftEventHandler {
-
- public static void SendHandLer(Player zhubo,String userName,String eventName){
- Game game = ColorblindWar.getGame();
- userName = GameUtil.HideName(userName);
- if (eventName.equalsIgnoreCase("致盲")){
-
- }
- }
-}
diff --git a/src/main/java/com/io/yutian/colorblindwar/manager/GiftEffectManager.java b/src/main/java/com/io/yutian/colorblindwar/manager/GiftEffectManager.java
new file mode 100644
index 0000000..26b0ad3
--- /dev/null
+++ b/src/main/java/com/io/yutian/colorblindwar/manager/GiftEffectManager.java
@@ -0,0 +1,72 @@
+package com.io.yutian.colorblindwar.manager;
+
+import com.io.yutian.colorblindwar.game.Game;
+import com.io.yutian.colorblindwar.live.GiftEffect;
+import com.io.yutian.colorblindwar.live.GiftQueue;
+import com.io.yutian.colorblindwar.util.RandomUtil;
+import org.bukkit.entity.Player;
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.potion.PotionEffectType;
+
+import java.util.*;
+import java.util.function.Function;
+
+public class GiftEffectManager {
+
+ private static Map> giftEffectMap = new HashMap<>();
+
+ private static Map giftQueues = new HashMap<>();
+
+ public static void addGiftEffect(String audience, String effectId) {
+ GiftEffect giftEffect = giftEffectMap.get(effectId).apply(audience);
+ GiftQueue giftQueue = giftQueues.getOrDefault(effectId, new GiftQueue(giftEffect.getQueueTime()));
+ giftQueue.addEffect(giftEffect);
+ giftQueues.put(effectId, giftQueue);
+ }
+
+ public static GiftQueue getGiftQueue(String effectId) {
+ return giftQueues.get(effectId);
+ }
+
+ public static Map getGiftQueues() {
+ return giftQueues;
+ }
+
+ public static void registerAll() {
+ registerGiftEffect("盲盒", (audience)-> new GiftEffect(audience) {
+
+ private static List effects = new ArrayList<>();
+
+ static {
+ effects.add("致盲");
+ }
+
+ @Override
+ public void apply(Game game) {
+ Player player = game.getPlayer();
+ String effect = effects.get(RandomUtil.getRandomInt(0, effects.size() - 1));
+ addGiftEffect(audience, effect);
+ }
+ @Override
+ public int getQueueTime() {
+ return 20;
+ }
+ });
+ registerGiftEffect("致盲", (audience)-> new GiftEffect(audience) {
+ @Override
+ public void apply(Game game) {
+ Player player = game.getPlayer();
+ player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20 * 3, 0, false, false));
+ }
+ @Override
+ public int getQueueTime() {
+ return 60;
+ }
+ });
+ }
+
+ private static void registerGiftEffect(String id, Function giftEffectGetter) {
+ giftEffectMap.put(id, giftEffectGetter);
+ }
+
+}
diff --git a/src/main/java/com/io/yutian/colorblindwar/util/GameUtil.java b/src/main/java/com/io/yutian/colorblindwar/util/GiftUtil.java
similarity index 74%
rename from src/main/java/com/io/yutian/colorblindwar/util/GameUtil.java
rename to src/main/java/com/io/yutian/colorblindwar/util/GiftUtil.java
index 61c5ec3..c126245 100644
--- a/src/main/java/com/io/yutian/colorblindwar/util/GameUtil.java
+++ b/src/main/java/com/io/yutian/colorblindwar/util/GiftUtil.java
@@ -5,16 +5,14 @@ import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-public class GameUtil {
+public class GiftUtil {
- public static String HideName(String audience){
- if(audience.length() <= 2){
+ 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('*');
@@ -22,10 +20,11 @@ public class GameUtil {
return String.valueOf(firstChar) + maskedString + lastChar;
}
- public static void SendMessage(CommandSender sender, String message){
- sender.sendMessage("§c[系统]§a"+message);
+ public static void sendMessage(CommandSender sender, String message) {
+ sender.sendMessage("§c[系统]§a" + message);
}
- public static void SendAllSounds(String sound){
+
+ public static void sendAllSound(String sound) {
for (Player player : Bukkit.getOnlinePlayers()) {
if (sound.contains("_")) {
player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1);
@@ -35,7 +34,7 @@ public class GameUtil {
}
}
- public static boolean specialGiftEffectTriggers(Player player,String eventName,String show_userName,int amount) {
+ public static boolean specialGiftEffectTriggers(Player player, String eventName, String show_userName, int amount) {
if (eventName.contains("盲盒")) {
if (eventName.contains("#")) {
String s1 = "love";
@@ -44,11 +43,12 @@ public class GameUtil {
if (eventName.contains("X")) {
amount = Integer.parseInt(eventName.split("X")[1]);
}
- RBoxAPI.addUserData(player, show_userName, box, amount);
+ //RBoxAPI.addUserData(player, show_userName, box, amount);
} else {
System.out.println("[错误 - 盲盒] 随机盲盒在礼物设置中配置错误.");
}
return true;
}
+ return false;
}
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 86a43e5..7280182 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,5 +1,5 @@
name: ColorblindWar
-version: '${project.version}'
+version: '1.1'
main: com.io.yutian.colorblindwar.ColorblindWar
api-version: '1.18'
depend: