2
0
Эх сурвалжийг харах

add config option for spawn and respawn items

RedstoneFuture 3 жил өмнө
parent
commit
d443d7e325

+ 84 - 15
missilewars-plugin/src/main/java/de/butzlabben/missilewars/game/Game.java

@@ -97,6 +97,8 @@ public class Game {
     private Scoreboard scoreboard;
     private ScoreboardManager scoreboardManager;
     private GameBoundListener listener;
+    private ItemStack customBow;
+    private ItemStack customPickaxe;
 
     public Game(Lobby lobby) {
         Logger.BOOT.log("Loading game " + lobby.getDisplayName());
@@ -208,6 +210,8 @@ public class Game {
 
         FightStats.checkTables();
         Logger.DEBUG.log("Fights: " + fights);
+
+        createGameItems();
     }
 
     public void startGame() {
@@ -390,25 +394,90 @@ public class Game {
         }
 
         player.teleport(mwPlayer.getTeam().getSpawn());
-        ItemStack air = new ItemStack(Material.AIR);
-        ItemStack bow = new ItemStack(Material.BOW);
-        bow.addEnchantment(Enchantment.ARROW_FIRE, 1);
-        bow.addEnchantment(Enchantment.ARROW_DAMAGE, 1);
-        bow.addEnchantment(Enchantment.ARROW_KNOCKBACK, 1);
-        ItemMeta im = bow.getItemMeta();
-        im.addEnchant(Enchantment.DAMAGE_ALL, 6, true);
-        bow.setItemMeta(im);
-        VersionUtil.setUnbreakable(bow);
-
-        player.getInventory().setItem(0, air);
-        player.getInventory().setItem(8, air);
-        player.getInventory().addItem(bow);
+
+        sendGameItems(player, false);
+        setPlayerAttributes(player);
+
         mwPlayer.getTeam().setTeamArmor(player);
+
+        playerTasks.put(player.getUniqueId(),
+                Bukkit.getScheduler().runTaskTimer(MissileWars.getInstance(), mwPlayer, 0, 20));
+
+    }
+
+    /**
+     * This methode create the game items for the player kit.
+     */
+    private void createGameItems() {
+
+        // Will it be used ?
+        if (this.getArena().getSpawn().isSendBow() || this.getArena().getRespawn().isSendBow()) {
+
+            ItemStack bow = new ItemStack(Material.BOW);
+            bow.addEnchantment(Enchantment.ARROW_FIRE, 1);
+            bow.addEnchantment(Enchantment.ARROW_DAMAGE, 1);
+            bow.addEnchantment(Enchantment.ARROW_KNOCKBACK, 1);
+            ItemMeta im = bow.getItemMeta();
+            im.addEnchant(Enchantment.DAMAGE_ALL, 6, true);
+            bow.setItemMeta(im);
+            VersionUtil.setUnbreakable(bow);
+            this.customBow = bow;
+        }
+
+        // Will it be used ?
+        if (this.getArena().getSpawn().isSendPickaxe() || this.getArena().getRespawn().isSendPickaxe()) {
+
+            ItemStack pickaxe = new ItemStack(Material.IRON_PICKAXE);
+            this.customPickaxe = pickaxe;
+        }
+
+    }
+
+    /**
+     * This methode give the player the starter item set, based on the
+     * config.yml configuration for spawn and respawn items.
+     *
+     * @param player the target player
+     * @param isRespawn true, if the player should get it after a respawn
+     */
+    public void sendGameItems(Player player, boolean isRespawn) {
+
+        player.getInventory().clear();
+
+        if (isRespawn) {
+
+            if (this.getArena().getRespawn().isSendBow()) {
+                player.getInventory().addItem(this.customBow);
+            }
+
+            if (this.getArena().getRespawn().isSendPickaxe()) {
+                player.getInventory().addItem(this.customPickaxe);
+            }
+
+        } else {
+
+            if (this.getArena().getSpawn().isSendBow()) {
+                player.getInventory().addItem(this.customBow);
+            }
+
+            if (this.getArena().getSpawn().isSendPickaxe()) {
+                player.getInventory().addItem(this.customPickaxe);
+            }
+
+        }
+
+    }
+
+    /**
+     * This methode set the player attributes (game-mode, level, enchantments, ...)
+     *
+     * @param player the target player
+     */
+    public void setPlayerAttributes(Player player) {
+
         player.setGameMode(GameMode.SURVIVAL);
         player.setLevel(0);
         player.setFireTicks(0);
-        playerTasks.put(player.getUniqueId(),
-                Bukkit.getScheduler().runTaskTimer(MissileWars.getInstance(), mwPlayer, 0, 20));
 
     }
 

+ 25 - 13
missilewars-plugin/src/main/java/de/butzlabben/missilewars/listener/GameListener.java

@@ -254,35 +254,47 @@ public class GameListener extends GameBoundListener {
 
     @EventHandler
     public void onDeath(PlayerDeathEvent e) {
-        if (!isInGameWorld(e.getEntity().getLocation()))
+
+        // check if the player is in a game world
+        if (!isInGameWorld(e.getEntity().getLocation())) {
             return;
-        Game game = getGame();
+        }
 
+        Game game = getGame();
         Player p = e.getEntity();
-        e.setDeathMessage(MessageConfig.getNativeMessage("died").replace("%player%", p.getDisplayName()));
+
+        e.setDeathMessage(null);
+        // delete vanilla death message
+        String deathBroadcastMessage = null;
+
         MWPlayer player = getGame().getPlayer(p);
         assert player != null;
 
         if (game.getArena().isAutoRespawn()) Bukkit.getScheduler().runTaskLater(MissileWars.getInstance(), () -> p.spigot().respawn(), 20L);
 
+        // spectator respawn for people there are not in a team
         if (player.getTeam() == null) {
             p.setHealth(p.getMaxHealth());
             p.teleport(getGame().getArena().getSpectatorSpawn());
-            e.setDeathMessage(null);
             return;
         }
 
-        p.setGameMode(GameMode.SURVIVAL);
-        if (p.getLastDamageCause() != null)
-            if (p.getLastDamageCause().getCause() == EntityDamageEvent.DamageCause.BLOCK_EXPLOSION
-                    || p.getLastDamageCause().getCause() == EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) {
-                e.setDeathMessage(
-                        MessageConfig.getNativeMessage("died_explosion").replace("%player%", p.getDisplayName()));
+        game.sendGameItems(p, true);
+        game.setPlayerAttributes(p);
+
+        // check the death cause for choice the death message
+        if (p.getLastDamageCause() != null) {
+
+            EntityDamageEvent.DamageCause demageCause = p.getLastDamageCause().getCause();
+
+            if (demageCause == EntityDamageEvent.DamageCause.BLOCK_EXPLOSION || demageCause == EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) {
+                deathBroadcastMessage = MessageConfig.getNativeMessage("died_explosion").replace("%player%", p.getDisplayName());
+            } else {
+                deathBroadcastMessage = MessageConfig.getNativeMessage("died").replace("%player%", p.getDisplayName());
             }
+        }
 
-        String msg = e.getDeathMessage();
-        e.setDeathMessage(null);
-        getGame().broadcast(msg);
+        getGame().broadcast(deathBroadcastMessage);
     }
 
     @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)

+ 3 - 5
missilewars-plugin/src/main/java/de/butzlabben/missilewars/wrapper/abstracts/Arena.java

@@ -20,11 +20,7 @@ package de.butzlabben.missilewars.wrapper.abstracts;
 
 import com.google.gson.annotations.SerializedName;
 import de.butzlabben.missilewars.Logger;
-import de.butzlabben.missilewars.wrapper.abstracts.arena.FallProtectionConfiguration;
-import de.butzlabben.missilewars.wrapper.abstracts.arena.FireballConfiguration;
-import de.butzlabben.missilewars.wrapper.abstracts.arena.MissileConfiguration;
-import de.butzlabben.missilewars.wrapper.abstracts.arena.MoneyConfiguration;
-import de.butzlabben.missilewars.wrapper.abstracts.arena.ShieldConfiguration;
+import de.butzlabben.missilewars.wrapper.abstracts.arena.*;
 import de.butzlabben.missilewars.wrapper.geometry.FlatArea;
 import de.butzlabben.missilewars.wrapper.geometry.Plane;
 import java.util.Collections;
@@ -50,6 +46,8 @@ public class Arena {
     @SerializedName("display_material") private String displayMaterial = "STONE";
     @SerializedName("template_world") private String templateWorld = "default_map";
     @SerializedName("auto_respawn") private boolean autoRespawn = true;
+    @SerializedName("game_spawn") private GameSpawnConfiguration spawn = new GameSpawnConfiguration();
+    @SerializedName("game_respawn") private GameRespawnConfiguration respawn = new GameRespawnConfiguration();
     @SerializedName("do_tile_drops") private boolean doTileDrops = false;
     @SerializedName("max_height") private int maxHeight = 170;
     @SerializedName("death_height") private int deathHeight = 65;

+ 33 - 0
missilewars-plugin/src/main/java/de/butzlabben/missilewars/wrapper/abstracts/arena/GameRespawnConfiguration.java

@@ -0,0 +1,33 @@
+/*
+ * This file is part of MissileWars (https://github.com/Butzlabben/missilewars).
+ * Copyright (c) 2018-2021 Daniel Nägele.
+ *
+ * MissileWars is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * MissileWars is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MissileWars.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package de.butzlabben.missilewars.wrapper.abstracts.arena;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.ToString;
+
+@Getter
+@ToString
+@RequiredArgsConstructor
+public class GameRespawnConfiguration {
+
+    @SerializedName("send_bow") private final boolean sendBow = true;
+    @SerializedName("send_pickaxe") private final boolean sendPickaxe = false;
+}

+ 33 - 0
missilewars-plugin/src/main/java/de/butzlabben/missilewars/wrapper/abstracts/arena/GameSpawnConfiguration.java

@@ -0,0 +1,33 @@
+/*
+ * This file is part of MissileWars (https://github.com/Butzlabben/missilewars).
+ * Copyright (c) 2018-2021 Daniel Nägele.
+ *
+ * MissileWars is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * MissileWars is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MissileWars.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package de.butzlabben.missilewars.wrapper.abstracts.arena;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.ToString;
+
+@Getter
+@ToString
+@RequiredArgsConstructor
+public class GameSpawnConfiguration {
+
+    @SerializedName("send_bow") private final boolean sendBow = true;
+    @SerializedName("send_pickaxe") private final boolean sendPickaxe = false;
+}