Browse Source

Merge pull request #7 from RedstoneFuture/features/starterkit

add: starter kit feature
Daniel 3 năm trước cách đây
mục cha
commit
a2e9259609

+ 93 - 16
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());
@@ -135,6 +137,9 @@ public class Game {
         team1 = new Team(lobby.getTeam1Name(), lobby.getTeam1Color(), this);
         team2 = new Team(lobby.getTeam2Name(), lobby.getTeam2Color(), this);
 
+        team1.createTeamArmor();
+        team2.createTeamArmor();
+
         scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
 
         org.bukkit.scoreboard.Team t = scoreboard.getTeam("0" + team1.getFullname());
@@ -208,6 +213,8 @@ public class Game {
 
         FightStats.checkTables();
         Logger.DEBUG.log("Fights: " + fights);
+
+        createGameItems();
     }
 
     public void startGame() {
@@ -390,25 +397,95 @@ 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);
-        mwPlayer.getTeam().setTeamArmor(player);
+
+        sendGameItems(player, false);
+        setPlayerAttributes(player);
+
+        playerTasks.put(player.getUniqueId(),
+                Bukkit.getScheduler().runTaskTimer(MissileWars.getInstance(), mwPlayer, 0, 20));
+
+    }
+
+    /**
+     * This method is used to 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);
+            VersionUtil.setUnbreakable(pickaxe);
+            this.customPickaxe = pickaxe;
+        }
+
+    }
+
+    /**
+     * This method gives the player the starter item set, based on the config.yml
+     * configuration for spawn and respawn.
+     *
+     * @param player the target player
+     * @param isRespawn true, if the player should receive it after a respawn
+     */
+    public void sendGameItems(Player player, boolean isRespawn) {
+
+        // clear inventory
+        player.getInventory().clear();
+
+        // send armor
+        ItemStack[] armor = getPlayer(player).getTeam().getTeamArmor();
+        player.getInventory().setArmorContents(armor);
+
+        // send kit items
+        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 method sets 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));
 
     }
 

+ 30 - 15
missilewars-plugin/src/main/java/de/butzlabben/missilewars/listener/GameListener.java

@@ -241,48 +241,63 @@ public class GameListener extends GameBoundListener {
         if (!isInGameWorld(e.getPlayer().getLocation()))
             return;
 
-        Team t = Objects.requireNonNull(getGame().getPlayer(e.getPlayer())).getTeam();
+        Game game = getGame();
+        Player player = e.getPlayer();
+
+        Team t = Objects.requireNonNull(getGame().getPlayer(player)).getTeam();
         if (t != null) {
             e.setRespawnLocation(t.getSpawn());
             FallProtectionConfiguration fallProtection = getGame().getArena().getFallProtection();
             if (fallProtection.isEnabled())
-                new RespawnGoldBlock(e.getPlayer(), fallProtection.getDuration(), fallProtection.isMessageOnlyOnStart(), getGame());
+                new RespawnGoldBlock(player, fallProtection.getDuration(), fallProtection.isMessageOnlyOnStart(), getGame());
         } else {
             e.setRespawnLocation(getGame().getArena().getSpectatorSpawn());
         }
+
+        game.sendGameItems(player, true);
+        game.setPlayerAttributes(player);
     }
 
     @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()));
+        // check the death cause for choice the death message
+        if (p.getLastDamageCause() != null) {
+
+            EntityDamageEvent.DamageCause damageCause = p.getLastDamageCause().getCause();
+
+            if (damageCause == EntityDamageEvent.DamageCause.BLOCK_EXPLOSION || damageCause == 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;

+ 2 - 2
missilewars-plugin/src/main/java/de/butzlabben/missilewars/wrapper/abstracts/arena/FireballConfiguration.java

@@ -28,7 +28,7 @@ import lombok.ToString;
 @RequiredArgsConstructor
 public class FireballConfiguration {
 
-    private final String name = "&cFireball";
-    private final int occurrence = 2;
+    private String name = "Fireball";
+    private int occurrence = 2;
     @SerializedName("destroy_portal") private boolean destroysPortal = false;
 }

+ 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 boolean sendBow = true;
+    @SerializedName("send_pickaxe") private 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 boolean sendBow = true;
+    @SerializedName("send_pickaxe") private boolean sendPickaxe = false;
+}

+ 7 - 7
missilewars-plugin/src/main/java/de/butzlabben/missilewars/wrapper/abstracts/arena/MissileConfiguration.java

@@ -40,13 +40,13 @@ public class MissileConfiguration {
 
     // TODO pretty names
 
-    private final boolean onlyBlockPlaceable = false;
-    private final boolean onlyBetweenSpawnPlaceable = false;
-    private final boolean northFacing = true;
-    private final boolean eastFacing = true;
-    private final boolean southFacing = true;
-    private final boolean westFacing = true;
-    private final List<Missile> missiles = new ArrayList<Missile>() {{
+    private boolean onlyBlockPlaceable = false;
+    private boolean onlyBetweenSpawnPlaceable = false;
+    private boolean northFacing = true;
+    private boolean eastFacing = true;
+    private boolean southFacing = true;
+    private boolean westFacing = true;
+    private List<Missile> missiles = new ArrayList<Missile>() {{
         add(new Missile("Tomahawk.schematic", "&aTomahawk", EntityType.CREEPER, 2, 2, 3));
         add(new Missile("Cruiser.schematic", "&eCruiser", EntityType.BLAZE, 2, 2, 2));
         add(new Missile("Sword.schematic", "&7Sword", EntityType.SKELETON, 2, 2, 2));

+ 3 - 3
missilewars-plugin/src/main/java/de/butzlabben/missilewars/wrapper/abstracts/arena/MoneyConfiguration.java

@@ -27,7 +27,7 @@ import lombok.ToString;
 @RequiredArgsConstructor
 public class MoneyConfiguration {
 
-    private final int win = 80;
-    private final int loss = 50;
-    private final int draw = 30;
+    private int win = 80;
+    private int loss = 50;
+    private int draw = 30;
 }

+ 3 - 3
missilewars-plugin/src/main/java/de/butzlabben/missilewars/wrapper/abstracts/arena/ShieldConfiguration.java

@@ -28,8 +28,8 @@ import lombok.ToString;
 @RequiredArgsConstructor
 public class ShieldConfiguration {
 
-    private final String name = "Shield";
-    private final String schematic = "shield.schematic";
-    private final int occurrence = 1;
+    private String name = "Shield";
+    private String schematic = "shield.schematic";
+    private int occurrence = 1;
     @SerializedName("serialized_name") private int flyTime = 20;
 }

+ 37 - 29
missilewars-plugin/src/main/java/de/butzlabben/missilewars/wrapper/game/Team.java

@@ -58,6 +58,7 @@ public class Team {
     private transient boolean won;
     private transient org.bukkit.scoreboard.Team scoreboardTeam;
     private transient int currentInterval = 0;
+    ItemStack[] teamArmor;
 
     public ArrayList<MWPlayer> getMembers() {
         return members;
@@ -105,7 +106,7 @@ public class Team {
         if (sb.getPlayerTeam(p) != null)
             sb.getPlayerTeam(p).removePlayer(p);
         scoreboardTeam.addPlayer(p);
-        setTeamArmor(p);
+        p.getInventory().setArmorContents(getTeamArmor());
     }
 
     public org.bukkit.scoreboard.Team getSBTeam() {
@@ -126,34 +127,41 @@ public class Team {
         return color;
     }
 
-    public void setTeamArmor(Player p) {
-        Color c = ColorConverter.getColorFromCode(getColorCode());
-        ItemStack is = new ItemStack(Material.LEATHER_BOOTS);
-        LeatherArmorMeta lam = (LeatherArmorMeta) is.getItemMeta();
-        lam.setColor(c);
-        is.setItemMeta(lam);
-        VersionUtil.setUnbreakable(is);
-
-        ItemStack is1 = new ItemStack(Material.LEATHER_LEGGINGS);
-        LeatherArmorMeta lam1 = (LeatherArmorMeta) is1.getItemMeta();
-        lam1.setColor(c);
-        is1.setItemMeta(lam1);
-        VersionUtil.setUnbreakable(is1);
-
-        ItemStack is2 = new ItemStack(Material.LEATHER_CHESTPLATE);
-        LeatherArmorMeta lam2 = (LeatherArmorMeta) is2.getItemMeta();
-        lam2.setColor(c);
-        is2.setItemMeta(lam2);
-        VersionUtil.setUnbreakable(is2);
-
-        ItemStack is3 = new ItemStack(Material.LEATHER_HELMET);
-        LeatherArmorMeta lam3 = (LeatherArmorMeta) is3.getItemMeta();
-        lam3.setColor(c);
-        is3.setItemMeta(lam3);
-        VersionUtil.setUnbreakable(is3);
-
-        ItemStack[] armor = new ItemStack[] {is, is1, is2, is3};
-        p.getInventory().setArmorContents(armor);
+    /**
+     * This method creates the team armor based on the team color.
+     */
+    public void createTeamArmor() {
+        Color color = ColorConverter.getColorFromCode(getColorCode());
+
+        ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
+        LeatherArmorMeta bootsMeta = (LeatherArmorMeta) boots.getItemMeta();
+        bootsMeta.setColor(color);
+        boots.setItemMeta(bootsMeta);
+        VersionUtil.setUnbreakable(boots);
+
+        ItemStack leggings = new ItemStack(Material.LEATHER_LEGGINGS);
+        LeatherArmorMeta leggingsMeta = (LeatherArmorMeta) leggings.getItemMeta();
+        leggingsMeta.setColor(color);
+        leggings.setItemMeta(leggingsMeta);
+        VersionUtil.setUnbreakable(leggings);
+
+        ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE);
+        LeatherArmorMeta chestplateMeta = (LeatherArmorMeta) chestplate.getItemMeta();
+        chestplateMeta.setColor(color);
+        chestplate.setItemMeta(chestplateMeta);
+        VersionUtil.setUnbreakable(chestplate);
+
+        ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
+        LeatherArmorMeta helmetMeta = (LeatherArmorMeta) helmet.getItemMeta();
+        helmetMeta.setColor(color);
+        helmet.setItemMeta(helmetMeta);
+        VersionUtil.setUnbreakable(helmet);
+
+        teamArmor = new ItemStack[] {boots, leggings, chestplate, helmet};
+    }
+
+    public ItemStack[] getTeamArmor() {
+        return this.teamArmor;
     }
 
     public boolean isMember(MWPlayer player) {

BIN
missilewars-plugin/src/main/resources/MissileWars-Arena.zip