fix: fix bug
This commit is contained in:
parent
63c1546d4d
commit
e0eceb5138
@ -1,11 +1,11 @@
|
||||
package cn.wzpmc.hny.commands.hny;
|
||||
|
||||
import cn.wzpmc.hny.commands.hny.arguments.CustomItemArgumentType;
|
||||
import cn.wzpmc.hny.commands.hny.sub.BuyCommand;
|
||||
import cn.wzpmc.hny.commands.hny.sub.buy.BuyCommand;
|
||||
import cn.wzpmc.hny.commands.hny.sub.armor.ArmorUpgrade;
|
||||
import cn.wzpmc.hny.commands.hny.sub.buy.BuyMenuCommand;
|
||||
import cn.wzpmc.hny.games.PlayerDataManager;
|
||||
import cn.wzpmc.hny.pojo.CustomItem;
|
||||
import cn.wzpmc.hny.pojo.GlobalPlayerData;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
@ -31,6 +31,9 @@ public class HnyCommand implements MmgaCommand, Command<CommandSender> {
|
||||
).then(LiteralArgumentBuilder.<CommandSender>literal("buy")
|
||||
.then(RequiredArgumentBuilder.<CommandSender, CustomItem>argument("item", new CustomItemArgumentType())
|
||||
.executes(new BuyCommand()))
|
||||
.then(LiteralArgumentBuilder.<CommandSender>literal("menu")
|
||||
.executes(new BuyMenuCommand())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ public class ArmorUpgrade implements Command<CommandSender> {
|
||||
int armorHeadLevel = playerData.getArmorHeadLevel();
|
||||
if (armorHeadLevel == 0){
|
||||
if (money > 15){
|
||||
playerData.reduceMoney(15);
|
||||
playerData.addArmorHeadLevel();
|
||||
instance.savePlayerData(source);
|
||||
} else {
|
||||
@ -49,6 +50,7 @@ public class ArmorUpgrade implements Command<CommandSender> {
|
||||
source.sendMessage(Component.text("当前护甲已经为顶级").color(NamedTextColor.GOLD));
|
||||
return 0;
|
||||
}
|
||||
playerData.reduceMoney(20);
|
||||
playerData.addArmorHeadLevel();
|
||||
instance.savePlayerData(source);
|
||||
} else {
|
||||
@ -60,6 +62,7 @@ public class ArmorUpgrade implements Command<CommandSender> {
|
||||
int armorLegLevel = playerData.getArmorLegLevel();
|
||||
if (armorLegLevel == 0){
|
||||
if (money > 20){
|
||||
playerData.reduceMoney(20);
|
||||
playerData.addArmorLegLevel();
|
||||
instance.savePlayerData(source);
|
||||
} else {
|
||||
@ -67,6 +70,7 @@ public class ArmorUpgrade implements Command<CommandSender> {
|
||||
}
|
||||
}else {
|
||||
if (money > 30){
|
||||
playerData.reduceMoney(30);
|
||||
playerData.addArmorLegLevel();
|
||||
instance.savePlayerData(source);
|
||||
if (playerData.getArmorHeadLevel() >= 5){
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.wzpmc.hny.commands.hny.sub;
|
||||
package cn.wzpmc.hny.commands.hny.sub.buy;
|
||||
|
||||
import cn.wzpmc.hny.games.PlayerDataManager;
|
||||
import cn.wzpmc.hny.pojo.CustomItem;
|
@ -0,0 +1,13 @@
|
||||
package cn.wzpmc.hny.commands.hny.sub.buy;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class BuyMenuCommand implements Command<CommandSender> {
|
||||
@Override
|
||||
public int run(CommandContext<CommandSender> commandContext) throws CommandSyntaxException {
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -73,7 +73,18 @@ public class PlayerChangeWorld implements Listener {
|
||||
if (playerData.isShield()){
|
||||
inventory.setItemInOffHand(new ItemStack(Material.SHIELD));
|
||||
}
|
||||
inventory.addItem(new ItemStack(Material.DIAMOND_SWORD),new ItemStack(Material.DIAMOND_AXE),new ItemStack(Material.DIAMOND_PICKAXE));
|
||||
inventory.addItem(new ItemStack(Material.DIAMOND_SWORD),
|
||||
new ItemStack(Material.DIAMOND_AXE),
|
||||
new ItemStack(Material.DIAMOND_PICKAXE),
|
||||
new ItemStack(Material.END_STONE, 64),
|
||||
new ItemStack(Material.END_STONE, 64),
|
||||
new ItemStack(Material.END_STONE, 64),
|
||||
new ItemStack(Material.END_STONE, 64),
|
||||
new ItemStack(Material.END_STONE, 64),
|
||||
new ItemStack(Material.BOW),
|
||||
new ItemStack(Material.ARROW, 64),
|
||||
new ItemStack(Material.ARROW, 64)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,25 +21,26 @@ public class PlayerDamage implements Listener {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (event.getDamager() instanceof Player attacker){
|
||||
PlayerEffectManager effectManager = PlayerEffectManager.getInstance();
|
||||
double finalDamage = event.getFinalDamage();
|
||||
double playerHealth = player.getHealth();
|
||||
if (effectManager.hasEffect(player, PlayerEffectManager.Effects.RAINBOW_HEALTH)) {
|
||||
event.setDamage(0);
|
||||
double health = playerHealth;
|
||||
health += finalDamage / 2;
|
||||
if (health > 20){
|
||||
health = 20;
|
||||
}
|
||||
player.setHealth(health);
|
||||
effectManager.removeEffect(player, PlayerEffectManager.Effects.RAINBOW_HEALTH);
|
||||
}
|
||||
if (effectManager.hasEffect(player, PlayerEffectManager.Effects.POWER_WELDING)){
|
||||
event.setDamage(finalDamage * 2);
|
||||
player.damage(finalDamage, attacker);
|
||||
effectManager.removeEffect(player, PlayerEffectManager.Effects.POWER_WELDING);
|
||||
PlayerEffectManager effectManager = PlayerEffectManager.getInstance();
|
||||
double finalDamage = event.getFinalDamage();
|
||||
double playerHealth = player.getHealth();
|
||||
Entity damager = event.getDamager();
|
||||
if (effectManager.hasEffect(player, PlayerEffectManager.Effects.RAINBOW_HEALTH)) {
|
||||
event.setDamage(0);
|
||||
double health = playerHealth;
|
||||
health += finalDamage / 2;
|
||||
if (health > 20){
|
||||
health = 20;
|
||||
}
|
||||
player.setHealth(health);
|
||||
effectManager.removeEffect(player, PlayerEffectManager.Effects.RAINBOW_HEALTH);
|
||||
}
|
||||
if (effectManager.hasEffect(player, PlayerEffectManager.Effects.POWER_WELDING)){
|
||||
event.setDamage(finalDamage * 2);
|
||||
player.damage(finalDamage, damager);
|
||||
effectManager.removeEffect(player, PlayerEffectManager.Effects.POWER_WELDING);
|
||||
}
|
||||
if (damager instanceof Player attacker){
|
||||
if (effectManager.hasEffect(attacker, PlayerEffectManager.Effects.BADLY_HURT)){
|
||||
effectManager.addEffect(player, PlayerEffectManager.Effects.BE_BADLY_HURT, 5, TimeUnit.SECONDS);
|
||||
effectManager.removeEffect(attacker, PlayerEffectManager.Effects.BADLY_HURT);
|
||||
|
@ -24,12 +24,12 @@ public class PlayerDeath implements Listener {
|
||||
return;
|
||||
}
|
||||
if (effectManager.hasEffect(player, PlayerEffectManager.Effects.PUT_OFF)){
|
||||
event.setCancelled(true);
|
||||
player.setHealth(20);
|
||||
putOffs.put(player, System.currentTimeMillis() + 20000);
|
||||
effectManager.removeEffect(player, PlayerEffectManager.Effects.PUT_OFF);
|
||||
return;
|
||||
}
|
||||
player.getInventory().clear();
|
||||
event.setKeepInventory(true);
|
||||
event.setKeepLevel(true);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package cn.wzpmc.hny.events;
|
||||
|
||||
import cn.wzpmc.hny.games.DigGame;
|
||||
import cn.wzpmc.hny.games.GameStageManager;
|
||||
import cn.wzpmc.hny.games.enums.Games;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -12,6 +14,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
public class PlayerDestroyBlock implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerDestroyBlock(BlockBreakEvent event){
|
||||
if (GameStageManager.getInstance().isEnd(Games.GAME3)){
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
if (DigGame.isPlayerInGame(player)){
|
||||
Block block = event.getBlock();
|
||||
|
@ -1,6 +1,8 @@
|
||||
package cn.wzpmc.hny.events;
|
||||
|
||||
import cn.wzpmc.hny.games.GameStageManager;
|
||||
import cn.wzpmc.hny.games.PlayerDataManager;
|
||||
import cn.wzpmc.hny.games.enums.Games;
|
||||
import cn.wzpmc.hny.pojo.CustomItem;
|
||||
import cn.wzpmc.hny.pojo.GlobalPlayerData;
|
||||
import cn.wzpmc.hny.utils.ClickEventRegister;
|
||||
@ -42,7 +44,11 @@ public class PlayerInventoryClick implements Listener {
|
||||
for (Map.Entry<CustomItem, ClickEventRegister.ClickEvent> customItemClickEventEntry : ClickEventRegister.getClickEvents().entrySet()) {
|
||||
CustomItem key = customItemClickEventEntry.getKey();
|
||||
if (key.is(cursor)) {
|
||||
customItemClickEventEntry.getValue().onClick(key, event);
|
||||
if (GameStageManager.getInstance().isStart(Games.GAME5)){
|
||||
customItemClickEventEntry.getValue().onClick(key, event);
|
||||
}else {
|
||||
player.sendMessage(Component.text("道具仅在第五阶段可用"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,9 @@ public class PlayerMove implements Listener {
|
||||
if (world.getBlockAt(moveTo.getBlockX(), moveTo.getBlockY() - 1, moveTo.getBlockZ()).isEmpty()){
|
||||
return;
|
||||
}
|
||||
if (player.isJumping()){
|
||||
return;
|
||||
}
|
||||
for (Games value : Games.values()) {
|
||||
if (GameStageManager.getInstance().isUnlock(value)){
|
||||
continue;
|
||||
@ -78,7 +81,11 @@ public class PlayerMove implements Listener {
|
||||
BoxPosition boxPosition = value.getBoxPosition();
|
||||
if (boxPosition.isIn(moveTo)){
|
||||
player.showTitle(Title.title(Component.text("未解锁的区域").color(NamedTextColor.YELLOW), Component.text("前面的区域,以后再来探索吧").color(NamedTextColor.GREEN)));
|
||||
player.teleport(boxPosition.getNearestEdgePoint(moveTo));
|
||||
Location nearestEdgePoint = boxPosition.getNearestEdgePoint(moveTo);
|
||||
if (moveTo.y() < 150){
|
||||
nearestEdgePoint.setY(144);
|
||||
}
|
||||
player.teleport(nearestEdgePoint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -44,29 +44,13 @@ public class Tick extends BukkitRunnable {
|
||||
GameStageManager instance = GameStageManager.getInstance();
|
||||
PlayerDataManager playerDataManager = PlayerDataManager.getInstance();
|
||||
Collection<? extends Player> onlinePlayers = server.getOnlinePlayers();
|
||||
ScoreboardManager scoreboardManager = server.getScoreboardManager();
|
||||
Scoreboard mainScoreboard = scoreboardManager.getMainScoreboard();
|
||||
Team protect = mainScoreboard.getTeam("protect");
|
||||
for (Map.Entry<Player, Long> playerLongEntry : PlayerDeath.putOffs.entrySet()) {
|
||||
if (playerLongEntry.getValue() > System.currentTimeMillis()){
|
||||
if (playerLongEntry.getValue() < System.currentTimeMillis()){
|
||||
Player key = playerLongEntry.getKey();
|
||||
key.damage(key.getHealth());
|
||||
PlayerDeath.putOffs.remove(key);
|
||||
}
|
||||
}
|
||||
if (protect == null){
|
||||
protect = mainScoreboard.registerNewTeam("protect");
|
||||
protect.color(NamedTextColor.BLUE);
|
||||
protect.displayName(Component.text("[防守]"));
|
||||
protect.setAllowFriendlyFire(false);
|
||||
}
|
||||
Team attack = mainScoreboard.getTeam("attack");
|
||||
if (attack == null){
|
||||
attack = mainScoreboard.registerNewTeam("attack");
|
||||
attack.color(NamedTextColor.RED);
|
||||
attack.displayName(Component.text("[进攻]"));
|
||||
attack.setAllowFriendlyFire(false);
|
||||
}
|
||||
for (Player onlinePlayer : onlinePlayers) {
|
||||
if (effectManager.hasEffect(onlinePlayer, DISH)){
|
||||
effectManager.hideEffect(onlinePlayer, BE_BADLY_HURT);
|
||||
@ -80,18 +64,31 @@ public class Tick extends BukkitRunnable {
|
||||
String tickString = effectManager.getEffectAttr(onlinePlayer, TREAT, "tick");
|
||||
int tick = tickString == null ? 0 : Integer.parseInt(tickString);
|
||||
onlinePlayer.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20, 3, false));
|
||||
double health = onlinePlayer.getHealth();
|
||||
if (tick == 100){
|
||||
onlinePlayer.setHealth(onlinePlayer.getHealth() + 5);
|
||||
if (health >= 15){
|
||||
onlinePlayer.setHealth(20);
|
||||
}else {
|
||||
onlinePlayer.setHealth(health + 5);
|
||||
}
|
||||
effectManager.removeEffect(onlinePlayer, BE_BADLY_HURT);
|
||||
}
|
||||
if (tick == 140){
|
||||
onlinePlayer.setHealth(onlinePlayer.getHealth() + 6);
|
||||
if (health >= 19){
|
||||
onlinePlayer.setHealth(20);
|
||||
} else {
|
||||
onlinePlayer.setHealth(health + 1);
|
||||
}
|
||||
effectManager.removeEffect(onlinePlayer, BE_BADLY_HURT);
|
||||
effectManager.removeEffect(onlinePlayer, ERROR);
|
||||
|
||||
}
|
||||
if (tick == 200) {
|
||||
onlinePlayer.setHealth(onlinePlayer.getHealth() + 10);
|
||||
if (health >= 16){
|
||||
onlinePlayer.setHealth(20);
|
||||
}else {
|
||||
onlinePlayer.setHealth(health + 10);
|
||||
}
|
||||
effectManager.removeEffect(onlinePlayer, BE_BADLY_HURT);
|
||||
effectManager.removeEffect(onlinePlayer, ERROR);
|
||||
effectManager.removeEffect(onlinePlayer, MARK);
|
||||
@ -104,28 +101,6 @@ public class Tick extends BukkitRunnable {
|
||||
onlinePlayer.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20, 2, false));
|
||||
}
|
||||
}
|
||||
for (Player onlinePlayer : onlinePlayers) {
|
||||
GlobalPlayerData playerData = playerDataManager.getPlayerData(onlinePlayer);
|
||||
Teams team = playerData.getTeam();
|
||||
switch (team) {
|
||||
case ATTACK -> {
|
||||
if (protect.hasPlayer(onlinePlayer)){
|
||||
protect.removePlayer(onlinePlayer);
|
||||
}
|
||||
if (!attack.hasPlayer(onlinePlayer)) {
|
||||
attack.addPlayer(onlinePlayer);
|
||||
}
|
||||
}
|
||||
case PROTECT -> {
|
||||
if (attack.hasPlayer(onlinePlayer)){
|
||||
attack.removePlayer(onlinePlayer);
|
||||
}
|
||||
if (!protect.hasPlayer(onlinePlayer)) {
|
||||
protect.addPlayer(onlinePlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Games value : Games.values()) {
|
||||
if (instance.isNotStart(value) && instance.isUnlock(value)) {
|
||||
int size = instance.getVotePlayers(value).size();
|
||||
|
@ -55,9 +55,12 @@ public class DigGame implements AutoCloseable {
|
||||
this.playWorld.setHunger(false);
|
||||
this.playWorld.setTime("day");
|
||||
this.playWorld.setDifficulty(Difficulty.PEACEFUL);
|
||||
this.playWorld.setPVPMode(true);
|
||||
this.playWorld.setEnableWeather(false);
|
||||
World cbWorld = this.playWorld.getCBWorld();
|
||||
cbWorld.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
||||
cbWorld.setGameRule(GameRule.DO_MOB_SPAWNING, false);
|
||||
cbWorld.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
||||
this.playerJoinLocation = new Location(cbWorld, 15, 76, 15);
|
||||
this.playWorld.setSpawnLocation(this.playerJoinLocation);
|
||||
DigGame.games.add(this);
|
||||
|
@ -71,7 +71,11 @@ public class PlayerDataManager {
|
||||
erosionLevel = 0d;
|
||||
}
|
||||
Teams team = Teams.valueOf(persistentDataContainer.get(teamKey, PersistentDataType.INTEGER));
|
||||
boolean shield = Boolean.TRUE.equals(persistentDataContainer.get(shieldKey, PersistentDataType.BOOLEAN));
|
||||
Integer rawShieldData = persistentDataContainer.get(shieldKey, PersistentDataType.INTEGER);
|
||||
if (rawShieldData == null){
|
||||
rawShieldData = 0;
|
||||
}
|
||||
boolean shield = rawShieldData == 1;
|
||||
GlobalPlayerData globalPlayerData = new GlobalPlayerData(money, items, headLevel, legLevel, erosionLevel, team, shield);
|
||||
this.players.put(player, globalPlayerData);
|
||||
}
|
||||
@ -118,6 +122,14 @@ public class PlayerDataManager {
|
||||
players.clear();
|
||||
for (Player onlinePlayer : server.getOnlinePlayers()) {
|
||||
PersistentDataContainer persistentDataContainer = onlinePlayer.getPersistentDataContainer();
|
||||
persistentDataContainer.remove(moneyKey);
|
||||
persistentDataContainer.remove(itemKey);
|
||||
persistentDataContainer.remove(itemCountKey);
|
||||
persistentDataContainer.remove(armorLegKey);
|
||||
persistentDataContainer.remove(armorHeadKey);
|
||||
persistentDataContainer.remove(erosionKey);
|
||||
persistentDataContainer.remove(teamKey);
|
||||
persistentDataContainer.remove(shieldKey);
|
||||
persistentDataContainer.set(moneyKey, PersistentDataType.DOUBLE, 0d);
|
||||
persistentDataContainer.set(itemKey, PersistentDataType.INTEGER_ARRAY, new int[0]);
|
||||
persistentDataContainer.set(itemCountKey, PersistentDataType.INTEGER_ARRAY, new int[0]);
|
||||
@ -125,7 +137,7 @@ public class PlayerDataManager {
|
||||
persistentDataContainer.set(armorHeadKey, PersistentDataType.INTEGER, 0);
|
||||
persistentDataContainer.set(erosionKey, PersistentDataType.DOUBLE, 0d);
|
||||
persistentDataContainer.set(teamKey, PersistentDataType.INTEGER, Teams.ATTACK.getId());
|
||||
persistentDataContainer.set(shieldKey, PersistentDataType.BOOLEAN, false);
|
||||
persistentDataContainer.set(shieldKey, PersistentDataType.INTEGER, 0);
|
||||
this.initPlayerData(onlinePlayer);
|
||||
}
|
||||
}
|
||||
@ -149,6 +161,6 @@ public class PlayerDataManager {
|
||||
persistentDataContainer.set(armorLegKey, PersistentDataType.INTEGER, globalPlayerData.getArmorLegLevel());
|
||||
persistentDataContainer.set(erosionKey, PersistentDataType.DOUBLE, globalPlayerData.getErosionLevel());
|
||||
persistentDataContainer.set(teamKey, PersistentDataType.INTEGER, globalPlayerData.getTeam().getId());
|
||||
persistentDataContainer.set(shieldKey, PersistentDataType.BOOLEAN, globalPlayerData.isShield());
|
||||
persistentDataContainer.set(shieldKey, PersistentDataType.INTEGER, globalPlayerData.isShield() ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.wzpmc.hny.games;
|
||||
|
||||
import cn.wzpmc.hny.utils.IncreaseAbleConcurrentHashMap;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -11,6 +12,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@ -63,7 +65,7 @@ public class PlayerEffectManager {
|
||||
return this.attr.get(k);
|
||||
}
|
||||
}
|
||||
private static final IncreaseAbleHashMap<Player, EffectInfo> effectInfoMap = new IncreaseAbleHashMap<>();
|
||||
private static final IncreaseAbleConcurrentHashMap<Player, EffectInfo> effectInfoMap = new IncreaseAbleConcurrentHashMap<>();
|
||||
private static PlayerEffectManager instance;
|
||||
private PlayerEffectManager(){}
|
||||
public static PlayerEffectManager getInstance(){
|
||||
@ -73,7 +75,7 @@ public class PlayerEffectManager {
|
||||
return instance;
|
||||
}
|
||||
public boolean hasEffect(Player player, Effects effect){
|
||||
return effectInfoMap.getOrDefault(player, new ArrayList<>()).stream().anyMatch(e -> e.getType().equals(effect) && !e.isHidden());
|
||||
return effectInfoMap.getOrDefault(player, new CopyOnWriteArrayList<>()).stream().anyMatch(e -> e.getType().equals(effect) && !e.isHidden());
|
||||
}
|
||||
public String getEffectAttr(Player player, Effects effect, String k){
|
||||
for (EffectInfo effectInfo : effectInfoMap.get(player)) {
|
||||
@ -102,7 +104,7 @@ public class PlayerEffectManager {
|
||||
effectInfos.removeIf(e -> e.getType().equals(effects));
|
||||
}
|
||||
public void removeEffect(Player player){
|
||||
effectInfoMap.put(player, new ArrayList<>());
|
||||
effectInfoMap.put(player, new CopyOnWriteArrayList<>());
|
||||
}
|
||||
public void hideEffect(Player player, Effects effects){
|
||||
List<EffectInfo> effectInfos = effectInfoMap.get(player);
|
||||
|
@ -46,6 +46,7 @@ public class SumoGame implements AutoCloseable{
|
||||
private Player playerB;
|
||||
private int nowPrice = 0;
|
||||
private int nowRank = 1;
|
||||
private boolean isWaiting = false;
|
||||
public SumoGame() throws WorldCreateException {
|
||||
this.plugin = HappyNewLobby.getPlugin(HappyNewLobby.class);
|
||||
this.server = this.plugin.getServer();
|
||||
@ -107,6 +108,7 @@ public class SumoGame implements AutoCloseable{
|
||||
this.playerB = allIn.get(1);
|
||||
new MessageBroadcast(Title.title(this.playerA.displayName().color(NamedTextColor.RED).append(Component.text(" VS ").color(NamedTextColor.GOLD)).append(this.playerB.displayName().color(NamedTextColor.BLUE)), Component.empty()), onlinePlayers).runTaskLater(this.plugin, 80);
|
||||
new BetterBukkitRunnable(() -> {
|
||||
this.isWaiting = false;
|
||||
this.playerA.teleport(this.aSpawn);
|
||||
this.playerB.teleport(this.bSpawn);
|
||||
this.playerA.setHealth(20);
|
||||
@ -129,21 +131,30 @@ public class SumoGame implements AutoCloseable{
|
||||
if (player.equals(game.playerA)){
|
||||
win = game.playerB;
|
||||
other = game.playerA;
|
||||
if (game.isWaiting){
|
||||
win.teleport(game.bSpawn);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (player.equals(game.playerB)){
|
||||
win = game.playerA;
|
||||
other = game.playerB;
|
||||
if (game.isWaiting){
|
||||
win.teleport(game.aSpawn);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (other == null || win == null){
|
||||
return;
|
||||
}
|
||||
win.showTitle(Title.title(Component.text("恭喜获胜!"), Component.empty()));
|
||||
game.isWaiting = true;
|
||||
for (Player onlinePlayer : game.server.getOnlinePlayers()) {
|
||||
onlinePlayer.showTitle(Title.title(Component.text("恭喜" + win.getName() + "获胜").color(NamedTextColor.GREEN), Component.empty()));
|
||||
}
|
||||
PlayerDataManager instance = PlayerDataManager.getInstance();
|
||||
GlobalPlayerData playerData = instance.getPlayerData(other);
|
||||
playerData.addMoney(game.nowPrice+=10);
|
||||
playerData.addMoney(game.nowPrice+=100);
|
||||
other.setGameMode(GameMode.SPECTATOR);
|
||||
other.teleport(game.playerJoinLocation);
|
||||
game.players.get(other).setRank(game.nowRank--);
|
||||
|
@ -12,6 +12,6 @@ public enum Teams {
|
||||
this.id = id;
|
||||
}
|
||||
public static Teams valueOf(Integer i){
|
||||
return i == 1 ? PROTECT : ATTACK;
|
||||
return i != null && i == 1 ? PROTECT : ATTACK;
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class Game3StageEvent extends StageEvent {
|
||||
Player key = e.getKey();
|
||||
PlayerDataManager instance = PlayerDataManager.getInstance();
|
||||
GlobalPlayerData playerData = instance.getPlayerData(key);
|
||||
playerData.addMoney(i.getAndAdd(10));
|
||||
playerData.addMoney(i.getAndAdd(100));
|
||||
instance.savePlayerData(key);
|
||||
});
|
||||
new BetterBukkitRunnable(() -> this.digGame.close()).runTaskLater(this.plugin, 100);
|
||||
|
@ -30,13 +30,13 @@ public class Game4StageEvent extends StageEvent {
|
||||
for (Player onlinePlayer : server.getOnlinePlayers()) {
|
||||
onlinePlayer.teleport(teleport);
|
||||
onlinePlayer.setGameMode(GameMode.ADVENTURE);
|
||||
onlinePlayer.setBedSpawnLocation(teleport);
|
||||
onlinePlayer.setBedSpawnLocation(teleport, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStageDone() {
|
||||
new StageDoneTask(this, 153.5, 144, 252).runTaskLater(this.plugin, 40);
|
||||
new StageDoneTask(this, 153.5, 144, 252, 90, -20).runTaskLater(this.plugin, 40);
|
||||
new BetterBukkitRunnable(() -> GameStageManager.getInstance().triggerGameStart(Games.GAME5)).runTaskLater(this.plugin, 50);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cn.wzpmc.hny.utils;
|
||||
import cn.wzpmc.hny.HappyNewLobby;
|
||||
import cn.wzpmc.hny.games.PlayerDataManager;
|
||||
import cn.wzpmc.hny.games.PlayerEffectManager;
|
||||
import cn.wzpmc.hny.games.enums.Teams;
|
||||
import cn.wzpmc.hny.pojo.CustomItem;
|
||||
import cn.wzpmc.hny.pojo.GlobalPlayerData;
|
||||
import lombok.Getter;
|
||||
@ -56,7 +57,10 @@ public class ClickEventRegister {
|
||||
HumanEntity human = view.getPlayer();
|
||||
if (human instanceof Player player) {
|
||||
if (apply.test(player)) {
|
||||
PlayerDataManager.getInstance().getPlayerData(player).reduceItem(item);
|
||||
PlayerDataManager instance = PlayerDataManager.getInstance();
|
||||
instance.getPlayerData(player).reduceItem(item);
|
||||
instance.showPlayerInventory(player);
|
||||
instance.savePlayerData(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -87,6 +91,11 @@ public class ClickEventRegister {
|
||||
addEvent(TURBINE, new EffectClickEvent(PlayerEffectManager.Effects.TURBINE, 5, TimeUnit.SECONDS));
|
||||
addEvent(MILK, new ConsumeClickEvent(player -> {PlayerEffectManager.getInstance().removeEffect(player);player.getActivePotionEffects().forEach(e -> player.removePotionEffect(e.getType())); return true;}));
|
||||
addEvent(EVOLUTION_CRYSTAL, new ConsumeClickEvent(player -> {
|
||||
PlayerDataManager instance = PlayerDataManager.getInstance();
|
||||
if (instance.getPlayerData(player).getTeam().equals(Teams.ATTACK)){
|
||||
player.sendMessage(Component.text("仅防守方可以使用!"));
|
||||
return false;
|
||||
}
|
||||
RayTraceResult rayTraceResult = player.rayTraceBlocks(10);
|
||||
if (rayTraceResult == null){
|
||||
player.sendMessage(Component.text("无法放置,请指向要放置的方块"));
|
||||
@ -126,13 +135,13 @@ public class ClickEventRegister {
|
||||
addEvent(PUT_OFF, new EffectClickEvent(PlayerEffectManager.Effects.PUT_OFF));
|
||||
addEvent(CODE, new EffectClickEvent(PlayerEffectManager.Effects.CODE));
|
||||
addEvent(SEED, new ConsumeClickEvent(player -> {
|
||||
BetterBukkitRunnable betterBukkitRunnable = new BetterBukkitRunnable(() -> {
|
||||
PlayerDataManager instance = PlayerDataManager.getInstance();
|
||||
instance.getPlayerData(player).addMoney(10);
|
||||
});
|
||||
HappyNewLobby plugin = HappyNewLobby.getPlugin(HappyNewLobby.class);
|
||||
for (int i = 0; i < 12000; i+= 1200) {
|
||||
betterBukkitRunnable.runTaskLater(plugin, i);
|
||||
new BetterBukkitRunnable(() -> {
|
||||
PlayerDataManager instance = PlayerDataManager.getInstance();
|
||||
instance.getPlayerData(player).addMoney(10);
|
||||
instance.savePlayerData(player);
|
||||
}).runTaskLater(plugin, i);
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
|
@ -0,0 +1,32 @@
|
||||
package cn.wzpmc.hny.utils;
|
||||
|
||||
import org.mmga.utils.utils.map.IncreaseAbleMap;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class IncreaseAbleConcurrentHashMap<K, V> extends ConcurrentHashMap<K, CopyOnWriteArrayList<V>> implements IncreaseAbleMap<K, V> {
|
||||
@Override
|
||||
public void add(K k, V v) {
|
||||
CopyOnWriteArrayList<V> vs = super.getOrDefault(k, new CopyOnWriteArrayList<>());
|
||||
vs.add(v);
|
||||
super.put(k, vs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(K k, V v) {
|
||||
CopyOnWriteArrayList<V> oldList = super.getOrDefault(k, new CopyOnWriteArrayList<>());
|
||||
if (!oldList.remove(v)) {
|
||||
return false;
|
||||
} else {
|
||||
super.put(k, oldList);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(K k, Consumer<? super V> consumer) {
|
||||
super.get(k).forEach(consumer);
|
||||
}
|
||||
}
|
@ -16,6 +16,13 @@ public class StageDoneTask extends BukkitRunnable {
|
||||
private final World game1World;
|
||||
private final Games game;
|
||||
private final Games nextGame;
|
||||
public StageDoneTask(StageEvent stageEvent, double x, double y, double z, float yaw, float pitch){
|
||||
this.server = stageEvent.getServer();
|
||||
this.game1World = server.getWorld("game1");
|
||||
this.location = new Location(game1World, x,y,z,yaw,pitch);
|
||||
this.game = stageEvent.getGame();
|
||||
this.nextGame = stageEvent.getNextGame();
|
||||
}
|
||||
public StageDoneTask(StageEvent stageEvent, double x, double y, double z){
|
||||
this.server = stageEvent.getServer();
|
||||
this.game1World = server.getWorld("game1");
|
||||
@ -28,7 +35,7 @@ public class StageDoneTask extends BukkitRunnable {
|
||||
for (Player onlinePlayer : server.getOnlinePlayers()) {
|
||||
onlinePlayer.setGameMode(GameMode.ADVENTURE);
|
||||
onlinePlayer.teleport(location);
|
||||
onlinePlayer.setBedSpawnLocation(location);
|
||||
onlinePlayer.setBedSpawnLocation(location, true);
|
||||
}
|
||||
this.game.getBoxPosition().triggerRedstoneLamp(game1World, true);
|
||||
GameStageManager.getInstance().setUnlock(this.nextGame, true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user