Преглед на файлове

Merge branch 'master' into fix/inventory-interaction

RedstoneFuture преди 1 година
родител
ревизия
0df6471892

+ 4 - 0
README.md

@@ -29,6 +29,10 @@ Contributions are always welcome, just fork this project, make your changes and
 All information about the Commands, Permissions, Placeholders and the Configuration can be found
 in our [Github Wiki](https://github.com/Butzlabben/missilewars/wiki).
 
+## Supporters / Project Partners
+
+[![Recommended and supported by RedstoneWorld](https://redstoneworld.de/bilder/kooperation/RedstoneWorld-Logo_small.png)](https://redstoneworld.de)
+
 ## Donate
 
 [![Donation link](https://www.paypalobjects.com/en_US/DK/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=naegele_daniel%40web.de&currency_code=EUR&source=url)

+ 1 - 1
missilewars-plugin/src/main/java/de/butzlabben/missilewars/commands/UserCommands.java

@@ -114,7 +114,7 @@ public class UserCommands extends BaseCommand {
         }
 
         // Would the number of team members be too far apart?
-        if (to != game.getNextTeam()) {
+        if (!game.isValidTeamSwitch(to)) {
             player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.TEAM_UNFAIR_TEAM_SIZE));
             return;
         }

+ 2 - 2
missilewars-plugin/src/main/java/de/butzlabben/missilewars/configuration/arena/FallProtectionConfiguration.java

@@ -28,7 +28,7 @@ import lombok.ToString;
 @RequiredArgsConstructor
 public class FallProtectionConfiguration {
 
-    private final boolean enabled = true;
-    private final int duration = 60;
+    private boolean enabled = true;
+    private int duration = 60;
     @SerializedName("message_only_on_start") private boolean messageOnlyOnStart = false;
 }

+ 29 - 3
missilewars-plugin/src/main/java/de/butzlabben/missilewars/game/Game.java

@@ -349,7 +349,7 @@ public class Game {
             player.setFoodLevel(20);
             player.setHealth(player.getMaxHealth());
 
-            Team team = getNextTeam();
+            Team team = getSmallerTeam();
             team.addMember(mwPlayer);
             player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.TEAM_TEAM_ASSIGNED).replace("%team%", team.getFullname()));
 
@@ -800,9 +800,9 @@ public class Game {
      * This method returns the next matching team for the next player to
      * join. It is always the smaller team.
      *
-     * @return (Team) the matched team to join
+     * @return (Team) the smaller team
      */
-    public Team getNextTeam() {
+    public Team getSmallerTeam() {
         if (team1.getMembers().size() > team2.getMembers().size()) {
             return team2;
         } else {
@@ -810,6 +810,32 @@ public class Game {
         }
     }
 
+    /**
+     * This method checks whether a team switch would be fair based on 
+     * the new team size. If no empty team results or if the team size 
+     * difference does not exceed a certain value, the switch is 
+     * considered acceptable.
+     * 
+     * @param targetTeam the new team
+     * @return (boolean) 'true' if it's a fair team switch
+     */
+    public boolean isValidTeamSwitch(Team targetTeam) {
+        
+        // original team sizes
+        int targetTeamSize = targetTeam.getMembers().size();
+        int currentTeamSize = targetTeam.getEnemyTeam().getMembers().size();
+        
+        // Preventing an empty team when previously both teams had at least one player:
+        if ((currentTeamSize == 1) && (targetTeamSize >= 1)) return false;
+
+        int diff = getSmallerTeam().getEnemyTeam().getMembers().size() - getSmallerTeam().getMembers().size();
+
+        // max team difference: 30% (rounded) of target team size
+        float maxDiff = Math.max(1, Math.round(targetTeamSize * 0.3));
+
+        return diff <= maxDiff;
+    }
+
     public boolean isPlayersMax() {
         int maxSize = lobby.getMaxSize();
         int currentSize = team1.getMembers().size() + team2.getMembers().size();