This commit is contained in:
YuTian 2024-08-18 20:20:51 +08:00
parent 23c490e26f
commit fcfb6ae03e
21 changed files with 102 additions and 47 deletions

View File

@ -75,7 +75,7 @@
<dependency>
<groupId>com.io.yutian</groupId>
<artifactId>PixelLiveAPI</artifactId>
<version>1.0.2</version>
<version>1.0.4</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -15,12 +15,12 @@ import org.bukkit.plugin.java.JavaPlugin;
public class EnderDragonWar extends JavaPlugin {
public static EnderDragonWar plugin;
public static Game game;
private static EnderDragonWar instance;
private static Game game;
@Override
public void onEnable() {
plugin = this;
instance = this;
if (!PixelLiveAPI.isInitialized()) {
Bukkit.getPluginManager().disablePlugin(this);
@ -29,6 +29,7 @@ public class EnderDragonWar extends JavaPlugin {
GiftEffectManager.registerAll();
GameSetting.load();
game = new Game();
Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
@ -46,4 +47,12 @@ public class EnderDragonWar extends JavaPlugin {
return true;
}
public static EnderDragonWar inst() {
return instance;
}
public static Game getGame() {
return game;
}
}

View File

@ -14,7 +14,7 @@ public abstract class GameGiftEffect extends GiftEffect {
@Override
public void apply() {
apply(EnderDragonWar.game);
apply(EnderDragonWar.getGame());
}
}

View File

@ -37,7 +37,7 @@ public class AddMaxHealthEffect extends GameGiftEffect {
}
count++;
}
}.runTaskTimer(EnderDragonWar.plugin, 0L, 1L);
}.runTaskTimer(EnderDragonWar.inst(), 0L, 1L);
}
@Override

View File

@ -55,7 +55,7 @@ public class BlackHoleEffect extends GameGiftEffect {
}
i++;
}
}.runTaskTimer(EnderDragonWar.plugin, 0L, 10L);
}.runTaskTimer(EnderDragonWar.inst(), 0L, 10L);
new BukkitRunnable() {
private Set<UUID> uuids = new HashSet<>();
@ -101,7 +101,7 @@ public class BlackHoleEffect extends GameGiftEffect {
}
}
}
}.runTaskTimer(EnderDragonWar.plugin, 0L, 5L);
}.runTaskTimer(EnderDragonWar.inst(), 0L, 5L);
new BukkitRunnable() {
private Set<UUID> uuids = new HashSet<>();
@ -134,7 +134,7 @@ public class BlackHoleEffect extends GameGiftEffect {
}
}
}
}.runTaskTimer(EnderDragonWar.plugin, 0L, 1L);
}.runTaskTimer(EnderDragonWar.inst(), 0L, 1L);
}
@Override

View File

@ -153,7 +153,7 @@ public class BomBomEffect extends GameGiftEffect {
}
count++;
}
}.runTaskTimer(EnderDragonWar.plugin, 0L, 15L);
}.runTaskTimer(EnderDragonWar.inst(), 0L, 15L);
new BukkitRunnable() {
private int count = 0;
@ -171,7 +171,7 @@ public class BomBomEffect extends GameGiftEffect {
bossBar.setTitle(flag ? "§4§l毁天灭地" : "§c§l毁天灭地");
count++;
}
}.runTaskTimer(EnderDragonWar.plugin, 0L, 5L);
}.runTaskTimer(EnderDragonWar.inst(), 0L, 5L);
new BukkitRunnable() {
private int count = 0;
@ -188,7 +188,7 @@ public class BomBomEffect extends GameGiftEffect {
armorStand.getWorld().spawnParticle(Particle.FLAME, location1, 5, 0.2, 1, 0.2, 0.01);
count++;
}
}.runTaskTimer(EnderDragonWar.plugin, 0L, 2L);
}.runTaskTimer(EnderDragonWar.inst(), 0L, 2L);
new BukkitRunnable() {
@Override
public void run() {
@ -211,7 +211,7 @@ public class BomBomEffect extends GameGiftEffect {
}
}
}
}.runTaskTimer(EnderDragonWar.plugin, 0L, 1L);
}.runTaskTimer(EnderDragonWar.inst(), 0L, 1L);
}
}

View File

@ -64,7 +64,7 @@ public class ClearInventoryEffect extends GameGiftEffect {
allays.add(allay);
count++;
}
}.runTaskTimer(EnderDragonWar.plugin, 10L, 4L);
}.runTaskTimer(EnderDragonWar.inst(), 10L, 4L);
}
@Override

View File

@ -27,7 +27,7 @@ public class FiveLightningEffect extends GameGiftEffect {
player.getWorld().strikeLightning(player.getLocation());
count++;
}
}.runTaskTimer(EnderDragonWar.plugin, 0, 10L);
}.runTaskTimer(EnderDragonWar.inst(), 0, 10L);
}
}

View File

@ -44,8 +44,8 @@ public class RandomBoxEffect extends GameGiftEffect {
player.playSound(player.getLocation(), Sound.BLOCK_COMPARATOR_CLICK, 1, 1);
i++;
}
}.runTaskTimer(EnderDragonWar.plugin, 0L, 5L);
EnderDragonWar.game.addTasks(task);
}.runTaskTimer(EnderDragonWar.inst(), 0L, 5L);
EnderDragonWar.getGame().addTasks(task);
}
private List<String> getEffects() {

View File

@ -59,7 +59,7 @@ public class SpawnEnderPortalEffect extends GameGiftEffect {
int platformWidth = 3;
int platformLength = 7;
int levelAmount = 15;
EnderDragonWar.game.takeLiveTime(60 * 6);
EnderDragonWar.getGame().takeLiveTime(60 * 6);
World world = game.getWorld();
Player player = game.getPlayer();
Location location = player.getLocation();

View File

@ -17,7 +17,7 @@ public class ToHeavenEffect extends GameGiftEffect {
public void apply(Game game) {
Player player = game.getPlayer();
double radius = 1.5D;
EnderDragonWar.game.takeLiveTime(60);
EnderDragonWar.getGame().takeLiveTime(60);
new BukkitRunnable() {
private int count = 0;
private double angle = 0;
@ -41,7 +41,7 @@ public class ToHeavenEffect extends GameGiftEffect {
}
count++;
}
}.runTaskTimer(EnderDragonWar.plugin, 0L, 1L);
}.runTaskTimer(EnderDragonWar.inst(), 0L, 1L);
}
@Override

View File

@ -39,7 +39,7 @@ public class WuHuJumpEffect extends GameGiftEffect {
location.getWorld().playSound(location, Sound.ENTITY_CREEPER_PRIMED, 1.0f, 1.0f);
i++;
}
}.runTaskTimer(EnderDragonWar.plugin, 2L, 1L);
}.runTaskTimer(EnderDragonWar.inst(), 2L, 1L);
game.addTasks(task);
}

View File

@ -103,7 +103,7 @@ public class Game {
liveTime = liveTime - 500;
updateBossBar();
}
}.runTaskTimer(EnderDragonWar.plugin, 0L, 10L));
}.runTaskTimer(EnderDragonWar.inst(), 0L, 10L));
}
public void rejoinGame(Player player) {
@ -161,11 +161,11 @@ public class Game {
this.dianzan += count;
}
public int getDianzan() {
public int getDianZan() {
return dianzan;
}
public void setDianzan(int dianzan) {
public void setDianZan(int dianzan) {
this.dianzan = dianzan;
}

View File

@ -6,10 +6,15 @@ public class GameSetting {
private static int dianzanAmount;
private static String dianzanEffect;
private static int deathAddTime;
public static void load() {
dianzanAmount = Integer.parseInt(PixelLiveAPI.getExtraDataManager().getConfigValue("点赞数量", "50"));
PixelLiveAPI.getExtraDataManager().addDefault("点赞数量", "50");
PixelLiveAPI.getExtraDataManager().addDefault("点赞效果", "幸运方块");
PixelLiveAPI.getExtraDataManager().addDefault("死亡增加时间", "5");
dianzanAmount = PixelLiveAPI.getExtraDataManager().getConfigValueInt("点赞数量", 50);
dianzanEffect = PixelLiveAPI.getExtraDataManager().getConfigValue("点赞效果", "幸运方块");
deathAddTime = PixelLiveAPI.getExtraDataManager().getConfigValueInt("死亡增加时间", 5);
}
public static int getDianzanAmount() {
@ -20,4 +25,8 @@ public class GameSetting {
return dianzanEffect;
}
public static int getDeathAddTime() {
return deathAddTime;
}
}

View File

@ -1,6 +1,7 @@
package com.yaohun.enderdragonwar.listener;
import com.yaohun.enderdragonwar.EnderDragonWar;
import com.yaohun.enderdragonwar.game.GameSetting;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.LightningStrike;
@ -25,12 +26,12 @@ public class GameListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
EnderDragonWar.game.startGame(player);
EnderDragonWar.getGame().startGame(player);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
EnderDragonWar.game.quitGame(event.getPlayer());
EnderDragonWar.getGame().quitGame(event.getPlayer());
}
@EventHandler
@ -64,19 +65,20 @@ public class GameListener implements Listener {
player.spigot().respawn();
}
if (i == 3) {
EnderDragonWar.game.addLiveTime(5);
player.sendTitle("§4你嘎了", "§e加播5分钟");
int t = GameSetting.getDeathAddTime();
EnderDragonWar.getGame().addLiveTime(t);
player.sendTitle("§4你嘎了", "§e加播"+t+"分钟!");
cancel();
}
i++;
}
}.runTaskTimer(EnderDragonWar.plugin, 0L, 2L);
}.runTaskTimer(EnderDragonWar.inst(), 0L, 2L);
}
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity() instanceof EnderDragon) {
EnderDragonWar.game.takeLiveTime(60);
EnderDragonWar.getGame().takeLiveTime(60);
}
}

View File

@ -26,7 +26,7 @@ public class LiveListener implements Listener {
}
@EventHandler
public void onDianZan(LiveLikeEvent event) {
public void onLiveLike(LiveLikeEvent event) {
Player zhubo = event.getPlayer();
String userName = "" + RandomUtil.getRandomInt(999, 10000);
Audience audience = event.getAudience();
@ -34,23 +34,22 @@ public class LiveListener implements Listener {
userName = audience.getNickName();
}
int count = event.getClickCount();
EnderDragonWar.game.addDianZan(count);
if (EnderDragonWar.game.getDianzan() >= GameSetting.getDianzanAmount()) {
EnderDragonWar.getGame().addDianZan(count);
if (EnderDragonWar.getGame().getDianZan() >= GameSetting.getDianzanAmount()) {
String event1 = GameSetting.getDianzanEffect();
String title = "§c" + event1;
String subtitle = "§9双击屏幕x" + GameSetting.getDianzanAmount();
zhubo.sendTitle(title, subtitle, 10, 30, 10);
PixelLiveAPI.getEffectQueueManager().addEffect(userName, event1, 1);
EnderDragonWar.game.setDianzan(0);
EnderDragonWar.getGame().setDianZan(0);
}
}
@EventHandler
public void onLive(LiveGiftEvent event) {
public void onLiveGift(LiveGiftEvent event) {
Player zhubo = event.getPlayer();
Audience audience = event.getAudience();
String userName = audience.getNickName();
boolean butt = userName != null;
Gift gift = event.getGift();
String giftName = gift.getName();
int giftAmount = event.getCount();
@ -65,9 +64,6 @@ public class LiveListener implements Listener {
title = "§c" + effect + " x" + giftAmount;
}
String subtitle = "§9" + giftName;
if (butt) {
subtitle = "§9" + hideUserName;
}
zhubo.sendTitle(title, subtitle, 0, 30, 10);
for (Player player : Bukkit.getOnlinePlayers()) {
player.sendMessage("§a礼物: §e" + hideUserName + " §d送来了 §e" + giftName + "x" + giftAmount);

View File

@ -76,7 +76,9 @@ public class PlayerListener implements Listener {
for (int j = 0; j <= 3; j++) {
for (int z = -3; z <= 3; z++) {
Block block = location.clone().add(i, j, z).getBlock();
block.setType(Material.AIR);
if (block.getType() == Material.LAVA) {
block.setType(Material.AIR);
}
}
}
}

View File

@ -274,7 +274,7 @@ public class BuildSpawner {
transformDirection();
count++;
}
}.runTaskTimer(EnderDragonWar.plugin, 0L, 3L);
}.runTaskTimer(EnderDragonWar.inst(), 0L, 3L);
}
@Override
@ -380,7 +380,7 @@ public class BuildSpawner {
transformDirection();
count++;
}
}.runTaskTimer(EnderDragonWar.plugin, 0L, 3L);
}.runTaskTimer(EnderDragonWar.inst(), 0L, 3L);
}
@Override

View File

@ -0,0 +1,37 @@
package com.yaohun.enderdragonwar.util;
import org.bukkit.plugin.Plugin;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.logging.Level;
public class FileUtil {
public static void saveFile(Plugin plugin, String resourcePath) {
resourcePath = resourcePath.replace('\\', '/');
InputStream in = plugin.getResource(resourcePath);
if (in == null) {
throw new IllegalArgumentException("Resource not found: " + resourcePath);
} else {
File outFile = new File(plugin.getDataFolder(), resourcePath);
int lastIndex = resourcePath.lastIndexOf(47);
File outDir = new File(plugin.getDataFolder(), resourcePath.substring(0, lastIndex >= 0 ? lastIndex : 0));
if (!outDir.exists()) {
outDir.mkdirs();
}
try {
Path target = outFile.toPath();
if (!outFile.exists()) {
Files.copy(in, target, StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException var10) {
IOException ex = var10;
plugin.getLogger().log(Level.SEVERE, "Could not save " + outFile.getName() + " to " + String.valueOf(outFile), ex);
}
}
}
}

View File

@ -16,17 +16,17 @@ import java.io.File;
public class WEUtil {
public static void loadSchematics(Location location, String fileName) {
File path = new File(EnderDragonWar.plugin.getDataFolder(), "schematics");
File path = new File(EnderDragonWar.inst().getDataFolder(), "schematics");
if (!path.exists()) {
path.mkdirs();
}
File schematicFile = new File(path, fileName + ".schem");
if (!schematicFile.exists()) {
EnderDragonWar.plugin.saveResource("schematics/" + fileName + ".schem", false);
EnderDragonWar.inst().saveResource("schematics/" + fileName + ".schem", false);
}
World world = location.getWorld();
EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(world));
Bukkit.getScheduler().runTaskAsynchronously(EnderDragonWar.plugin, () -> {
Bukkit.getScheduler().runTaskAsynchronously(EnderDragonWar.inst(), () -> {
try {
Clipboard clipboard = ClipboardFormats.findByFile(schematicFile).load(schematicFile);
clipboard.paste(BukkitAdapter.adapt(world), BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()));

View File

@ -1,5 +1,5 @@
name: EnderDragonWar
version: 1.0
version: 1.0.2
api-version: 1.20
main: com.yaohun.enderdragonwar.EnderDragonWar
depend: [PixelLiveAPI]