This commit is contained in:
YuTian 2024-08-06 10:24:10 +08:00
parent f7fbb02e8a
commit 0371c889ea
11 changed files with 239 additions and 36 deletions

16
pom.xml
View File

@ -23,8 +23,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<configuration> <configuration>
<source>${java.version}</source> <source>16</source>
<target>${java.version}</target> <target>16</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
@ -63,7 +63,11 @@
</repository> </repository>
<repository> <repository>
<id>public</id> <id>public</id>
<url>http://111.230.48.153:18081/repository/public/</url> <url>https://repo.aurora-pixels.com/repository/public/</url>
</repository>
<repository>
<id>public-rpg</id>
<url>https://repo.aurora-pixels.com/repository/public-rpg/</url>
</repository> </repository>
</repositories> </repositories>
@ -74,5 +78,11 @@
<version>1.18.2-R0.1-SNAPSHOT</version> <version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>fastasyncworldedit</artifactId>
<version>2.9.1</version>
<classifier>669</classifier>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -3,12 +3,16 @@ package com.io.yutian.colorblindwar;
import com.io.yutian.colorblindwar.game.DirectionPoint; import com.io.yutian.colorblindwar.game.DirectionPoint;
import com.io.yutian.colorblindwar.game.Game; import com.io.yutian.colorblindwar.game.Game;
import com.io.yutian.colorblindwar.listener.PlayerListener; 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.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.Map;
public final class ColorblindWar extends JavaPlugin { public final class ColorblindWar extends JavaPlugin {
private static ColorblindWar instance; private static ColorblindWar instance;
@ -17,10 +21,20 @@ public final class ColorblindWar extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
instance = this; instance = this;
GiftEffectManager.registerAll();
game = new Game(); game = new Game();
Bukkit.getPluginManager().registerEvents(new PlayerListener(), this); Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
} }
@Override
public void onDisable() {
if (game.isStarted()) {
game.stop(false);
}
}
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 0) { if (args.length == 0) {
@ -62,6 +76,24 @@ public final class ColorblindWar extends JavaPlugin {
} else if (subCommand.equalsIgnoreCase("reload")) { } else if (subCommand.equalsIgnoreCase("reload")) {
game.reload(); game.reload();
sender.sendMessage("重载成功"); 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<String, GiftQueue> entry : GiftEffectManager.getGiftQueues().entrySet()) {
String type = entry.getKey();
GiftQueue giftQueue = entry.getValue();
player.sendMessage(type+":");
player.sendMessage(" "+giftQueue.getEffectQueue().toString());
}
}
} }
} }
return true; return true;

View File

@ -1,4 +0,0 @@
package com.io.yutian.colorblindwar.effect;
public class EffectTime {
}

View File

@ -34,7 +34,6 @@ public class Game {
private static final List<Material> 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 static final List<Material> 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 World world;
private DirectionPoint spawnPoint; private DirectionPoint spawnPoint;
@ -146,6 +145,8 @@ public class Game {
for (Entity entity : entities) { for (Entity entity : entities) {
entity.remove(); entity.remove();
} }
spawnBuild();
this.bossBar1.removeAll(); this.bossBar1.removeAll();
this.bossBar2.removeAll(); this.bossBar2.removeAll();
this.bossBar3.removeAll(); this.bossBar3.removeAll();
@ -341,6 +342,10 @@ public class Game {
return started; return started;
} }
public Player getPlayer() {
return player;
}
public World getWorld() { public World getWorld() {
return world; return world;
} }

View File

@ -1,17 +1,45 @@
package com.io.yutian.colorblindwar.listener; package com.io.yutian.colorblindwar.listener;
import com.io.yutian.colorblindwar.ColorblindWar; 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.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.*; import org.bukkit.event.block.*;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.event.weather.WeatherChangeEvent;
public class PlayerListener implements Listener { 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 @EventHandler
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
if (ColorblindWar.getGame().isStarted()) { if (ColorblindWar.getGame().isStarted()) {

View File

@ -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;
}
}

View File

@ -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<GiftEffect> 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<GiftEffect> getEffectQueue() {
return effectQueue;
}
public BukkitTask getTask() {
return task;
}
}

View File

@ -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("致盲")){
}
}
}

View File

@ -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<String, Function<String, GiftEffect>> giftEffectMap = new HashMap<>();
private static Map<String, GiftQueue> 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<String, GiftQueue> getGiftQueues() {
return giftQueues;
}
public static void registerAll() {
registerGiftEffect("盲盒", (audience)-> new GiftEffect(audience) {
private static List<String> 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<String, GiftEffect> giftEffectGetter) {
giftEffectMap.put(id, giftEffectGetter);
}
}

View File

@ -5,16 +5,14 @@ import org.bukkit.Sound;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class GameUtil { public class GiftUtil {
public static String HideName(String audience){ public static String hideName(String audience) {
if (audience.length() <= 2) { if (audience.length() <= 2) {
return "**"; return "**";
} }
// 获取第一个和第二个字符
char firstChar = audience.charAt(0); char firstChar = audience.charAt(0);
char lastChar = audience.charAt(audience.length() - 1); char lastChar = audience.charAt(audience.length() - 1);
// 构建屏蔽后的字符串
StringBuilder maskedString = new StringBuilder(); StringBuilder maskedString = new StringBuilder();
for (int i = 1; i < audience.length() - 1; i++) { for (int i = 1; i < audience.length() - 1; i++) {
maskedString.append('*'); maskedString.append('*');
@ -22,10 +20,11 @@ public class GameUtil {
return String.valueOf(firstChar) + maskedString + lastChar; return String.valueOf(firstChar) + maskedString + lastChar;
} }
public static void SendMessage(CommandSender sender, String message){ public static void sendMessage(CommandSender sender, String message) {
sender.sendMessage("§c[系统]§a" + message); sender.sendMessage("§c[系统]§a" + message);
} }
public static void SendAllSounds(String sound){
public static void sendAllSound(String sound) {
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
if (sound.contains("_")) { if (sound.contains("_")) {
player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1); player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1);
@ -44,11 +43,12 @@ public class GameUtil {
if (eventName.contains("X")) { if (eventName.contains("X")) {
amount = Integer.parseInt(eventName.split("X")[1]); amount = Integer.parseInt(eventName.split("X")[1]);
} }
RBoxAPI.addUserData(player, show_userName, box, amount); //RBoxAPI.addUserData(player, show_userName, box, amount);
} else { } else {
System.out.println("[错误 - 盲盒] 随机盲盒在礼物设置中配置错误."); System.out.println("[错误 - 盲盒] 随机盲盒在礼物设置中配置错误.");
} }
return true; return true;
} }
return false;
} }
} }

View File

@ -1,5 +1,5 @@
name: ColorblindWar name: ColorblindWar
version: '${project.version}' version: '1.1'
main: com.io.yutian.colorblindwar.ColorblindWar main: com.io.yutian.colorblindwar.ColorblindWar
api-version: '1.18' api-version: '1.18'
depend: depend: