Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented option to force players to empty their inventories before

joining or watching.
  • Loading branch information...
commit 0d39ba225a95ff2eada1cd443747ddb687700ee5 1 parent dde1e17
@mkalus authored
View
16 src/main/java/de/beimax/simplespleef/game/GameStandard.java
@@ -464,6 +464,14 @@ public boolean join(Player player) {
return false;
}
+ // player has join with empty inventory?
+ if (configuration.getBoolean("emptyInventoryToJoin", false)) {
+ if (!InventoryKeeper.inventoryIsEmpty(player)) {
+ player.sendMessage(ChatColor.DARK_RED + SimpleSpleef.ll("errors.joinEmptyInventory"));
+ return false;
+ }
+ }
+
// check funds of player...
if (SimpleSpleef.economy != null) {
double entryFee = configuration.getDouble("entryFee", 0.0);
@@ -788,6 +796,14 @@ public boolean watch(Player player) {
return false;
}
+ // player has to watch with empty inventory?
+ if (configuration.getBoolean("emptyInventoryToSpectate", false)) {
+ if (!InventoryKeeper.inventoryIsEmpty(player)) {
+ player.sendMessage(ChatColor.DARK_RED + SimpleSpleef.ll("errors.watchEmptyInventory"));
+ return false;
+ }
+ }
+
// save spectator's original position
if (configuration.getBoolean("enableBackCommand", true))
SimpleSpleef.getOriginalPositionKeeper().keepPosition(player, false); // never change game mode here
View
20 src/main/java/de/beimax/simplespleef/gamehelpers/InventoryKeeper.java
@@ -8,6 +8,7 @@
import java.util.LinkedList;
import java.util.List;
+import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@@ -18,6 +19,25 @@
*/
public class InventoryKeeper {
/**
+ * Check players inventory if it is empty
+ * @param player
+ * @return true if empty
+ */
+ public static boolean inventoryIsEmpty(Player player) {
+ // check inventory contents for nun-null entries
+ for (ItemStack stack : player.getInventory().getContents())
+ if (stack != null && stack.getType() != Material.AIR) return false;
+
+ // check armor
+ for (ItemStack stack : player.getInventory().getArmorContents()) {
+ System.out.println(stack);
+ if (stack != null && stack.getType() != Material.AIR) return false;
+ }
+
+ return true;
+ }
+
+ /**
* inventory positions of armor
*/
public static final int HELMET = -10;
View
6 src/main/resources/config.yml
@@ -104,7 +104,11 @@ arenas:
# seconds for other players to ready. Once the timer expires, unready players will be kicked from the spleef game. If readyAutoStart has
# been set to true and enough players are available, the game will then start. Otherwise, the game will be ready to start via command/sign.
readyTimeout: 0
-# Clear inventory at game start and restore after game has ended
+# Require players to have an empty inventory and no armor when joining (keeps them from possibly losing their inventory when they log out)
+ emptyInventoryToJoin: false
+# Require spectators to have an empty inventory and no armor (they can't throw peanuts at the players)
+ emptyInventoryToSpectate: false
+# Clear inventory at game start and restore after game has ended (sometimes inventory cannot be restored when logging out)
clearInventory: false
# Add stuff the inventory? amount:item or amount:item:subid
addToInventory: false
View
2  src/main/resources/lang_de.yml
@@ -40,6 +40,7 @@ errors:
joinMax: 'Arena ist voll! Nur [NUMBER] Spleefer können in der Arena [ARENA] mitspielen.'
joinDouble: 'Du spielst bereits in der Arena [ARENA]. Du musst erst dieses Spiel verlassen, um an einem neuen Spiel teilnehmen zu können.'
joinFee: 'Du hast nicht die nötigen [AMOUNT], um am Spiel teilzunehmen.'
+ joinEmptyInventory: 'Bitte leere deine Taschen und lege deine Rüstung ab, bevor du am Spiel teilnimmst.'
teamNoGame: 'Du musst an einem Spleef teilnehmen, bevor du einem Team beitreten kannst!'
teamNotPossible: 'Die Arena [ARENA] unterstützt keine Team-Spiele.'
teamAlreadyStarted: 'Das Spiel läuft bereits in der Arena [ARENA].'
@@ -64,6 +65,7 @@ errors:
watchAlready: 'Du schaust dir bereits das Spiel in Arena [ARENA] an.'
watchNoSpawnDefined: 'Der Zuschauer-Spawn ist für Arena [ARENA] nicht definiert.'
watchSpleefer: 'Du bist Spleefer in der Arena [ARENA]. Du kannst nicht gleichzeitig Zuschauer sein!'
+ watchEmptyInventory: 'Bitte leere deine Taschen und lege deine Rüstung ab, bevor du ein Spiel anschaust.'
backNoLocation: 'Keinen ursprünglichen Ort gefunden.'
backSpleefer: 'Du bist Spleefer in der Arena [ARENA]. Du musst dein Spiel erst beenden, um zurück zu teleportieren.'
leave: 'Du spielst kein Spiel mit!'
View
2  src/main/resources/lang_en.yml
@@ -40,6 +40,7 @@ errors:
joinMax: 'Arena ist full! Only [NUMBER] spleefers can join a game in arena [ARENA].'
joinDouble: 'You are already player in arena [ARENA]. You have to leave this game first before joining another game.'
joinFee: 'You do not have the required [AMOUNT] to join the game.'
+ joinEmptyInventory: 'Please empty your inventory and take off your armor before joining a game.'
teamNoGame: 'You have to join a game before joining a team.'
teamNotPossible: 'The arena [ARENA] does not support team games.'
teamAlreadyStarted: 'There is already a game in progress in arena [ARENA].'
@@ -64,6 +65,7 @@ errors:
watchAlready: 'You are already watching a game in arena [ARENA].'
watchNoSpawnDefined: 'There is no spectator spawn defined for arena [ARENA].'
watchSpleefer: 'You are a spleefer in arena [ARENA]. You cannot watch at the same time!'
+ watchEmptyInventory: 'Please empty your inventory and take off your armor before watching a game.'
backNoLocation: 'No original location found.'
backSpleefer: 'You are a spleefer in arena [ARENA]. You have to leave the game before teleporting back.'
leave: 'You are not part of any game.'
Please sign in to comment.
Something went wrong with that request. Please try again.