Browse Source

Fixed /abba remove bug & added basic /abba info

lennartVH01 9 years ago
parent
commit
5fab7f9ce7

+ 30 - 8
config.yml

@@ -1,5 +1,32 @@
 # Abba Caving Plugin by lennartVH01
 
+# Game duration in seconds
+GameDuration: 1800
+
+# Times in game to notify players of the time left in seconds
+# Example: a NotifyTime of 120 will let all players know when there are 2 minutes left
+NotifyTimes:
+- 900
+- 300
+- 60
+
+# Max players per game, users with permission AbbaCaving.joinFull can still join
+PlayerCap: 10
+
+# Ratio of spoils given per player: 
+#   Top: first n players receive these chunks of total wins
+#   Pot: Amount to be added to general Pot
+#   All: Amount to be spread over all participants
+WinRatios:
+  All: 0.05
+  Pot: 0.05
+  Top:
+  - 0.6
+  - 0.2
+  - 0.1
+
+
+
 # Points awarded for each item at the end of an Abba Match
 ItemValues:
 - type: IRON_ORE
@@ -22,11 +49,6 @@ ItemValues:
 
 # Prohibited items, automatically includes entries in BlockValues
 Contraband:
-  - potion
-  - golden_apple
-
-# Game duration in seconds
-GameDuration: 1800
-
-# Max players per game, users with permission AbbaCaving.joinFull can still join
-PlayerCap: 10
+- type: GOLDEN_APPLE
+  damage: 0
+- type: POTION

+ 0 - 0
lang/en_US.lang


+ 2 - 0
plugin.yml

@@ -12,6 +12,8 @@ permissions:
     default: true
   AbbaCaving.info:
     default: true
+  AbbaCaving.list:
+    default: true
   AbbaCaving.joinFull:
     default: op
   AbbaCaving.create:

+ 10 - 38
src/me/lennartVH01/AbbaGame.java

@@ -2,49 +2,21 @@ package me.lennartVH01;
 
 
 
-import java.util.List;
-
 import org.bukkit.Location;
-import org.bukkit.inventory.Inventory;
-import org.bukkit.inventory.ItemStack;
 
 
 public class AbbaGame {
-	public boolean open = false;
+	
+	public boolean open;
 	public String name;
 	public Location spawn;
-	public static List<ValueItemPair> itemPairs;
-	
-	public static void initialize(List<ValueItemPair> valueItemPairs) {
-		itemPairs = valueItemPairs;
-		
-	}
+	public int duration;
 	
-	
-	
-	
-	public AbbaGame(Location spawn, String name){
-		this.spawn = spawn;
+	public AbbaGame(String name, Location spawn, int duration){
 		this.name = name;
-	}
-	
-	
-	public static calculatedScore calcScore(Inventory inv){
-		calculatedScore points = new calculatedScore(itemPairs);
-		
-		//might not be the most efficient, should probably use a HashMap for the itemPairs array
-		for(int i = 0; i < itemPairs.size(); i++){
-			ValueItemPair itemPair = itemPairs.get(i);
-			ItemStack compStack = itemPair.getItemStack();
-			int pointValue = itemPair.getValue();
-			for(ItemStack invStack:inv.getStorageContents()){
-				if(compStack.isSimilar(invStack)){
-					points.add(i, invStack.getAmount(), pointValue);
-				}
-			}
-		}
-		
-		return points;
+		this.spawn = spawn;
+		this.duration = duration;
+		this.open = false;
 	}
 	
 	public void open(){
@@ -56,7 +28,7 @@ public class AbbaGame {
 	public boolean isOpen(){
 		return open;
 	}
-
-
-	
+	public String getName(){
+		return name;
+	}
 }

+ 73 - 0
src/me/lennartVH01/AbbaTools.java

@@ -0,0 +1,73 @@
+package me.lennartVH01;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.bukkit.Location;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+
+
+
+public class AbbaTools {
+	public static List<ValueItemPair> itemPairs;
+	public static List<AbbaGame> games = new ArrayList<AbbaGame>();
+	
+	public static void initialize(List<ValueItemPair> valueItemPairs) {
+		itemPairs = valueItemPairs;
+		
+	}
+	
+	
+	
+	public static void create(String name, Location spawn, int duration){
+		AbbaGame game = new AbbaGame(name, spawn, duration);
+		games.add(game);
+	}
+	public static boolean removeAbbaGame(String name){
+		for(int i = 0; i < games.size(); i++){
+			if(games.get(i).name.equalsIgnoreCase(name)){
+				games.remove(i);
+				return true;
+			}
+		}
+		return false;
+	}
+	public static AbbaGame getAbbaGame(String name){
+		for(AbbaGame game:games){
+			if(game.name.equalsIgnoreCase(name)){
+				return game;
+			}
+		}
+		
+		return null;
+	}
+	public static AbbaGame getAbbaGame(){
+		if(games.size() >= 1){
+			return games.get(0);
+		}else{
+			return null;
+		}
+	}
+	
+	public static calculatedScore calcScore(Inventory inv){
+		calculatedScore points = new calculatedScore(itemPairs);
+		
+		//might not be the most efficient, should probably use a HashMap for the itemPairs array
+		for(int i = 0; i < itemPairs.size(); i++){
+			ValueItemPair itemPair = itemPairs.get(i);
+			ItemStack compStack = itemPair.getItemStack();
+			int pointValue = itemPair.getValue();
+			for(ItemStack invStack:inv.getStorageContents()){
+				if(compStack.isSimilar(invStack)){
+					points.add(i, invStack.getAmount(), pointValue);
+				}
+			}
+		}
+		
+		return points;
+	}
+	public static List<AbbaGame> getGames() {
+		return games;
+	}
+}

+ 66 - 10
src/me/lennartVH01/Main.java

@@ -14,7 +14,6 @@ import org.bukkit.command.CommandSender;
 import org.bukkit.configuration.file.FileConfiguration;
 import org.bukkit.entity.Player;
 import org.bukkit.inventory.ItemStack;
-import org.bukkit.plugin.PluginDescriptionFile;
 import org.bukkit.plugin.java.JavaPlugin;
 
 public class Main extends JavaPlugin{
@@ -44,9 +43,14 @@ public class Main extends JavaPlugin{
 	@Override
 	public void onEnable(){
 		
+		
+		
 		//Config
 		this.saveDefaultConfig();
 		
+		
+		
+		
 		// get Item Point Values
 		List<Map<?,?>> itemPointMaps = config.getMapList("ItemValues");
 		List<ValueItemPair> valueItemPairs = new ArrayList<ValueItemPair>();
@@ -64,7 +68,7 @@ public class Main extends JavaPlugin{
 			valueItemPairs.add(new ValueItemPair(stack, value));
 		}
 		
-		AbbaGame.initialize(valueItemPairs);
+		AbbaTools.initialize(valueItemPairs);
 		
 		
 	}
@@ -80,14 +84,49 @@ public class Main extends JavaPlugin{
 			}
 			switch(args[0].toLowerCase()){
 			case "join":
+				if(sender.hasPermission("AbbaGame.join")){
+					
+					
+					
+					
+				}else{
+					sender.sendMessage(Messages.noPermissionError);
+					return false;
+				}
 				
 				break;
 			case "leave":
 				
 				break;
 			case "info":
-				
+				if(sender.hasPermission("AbbaCaving.info")){
+					AbbaGame game;
+					if(args.length >= 2){
+						game = AbbaTools.getAbbaGame(args[1]);
+					}else{
+						game = AbbaTools.getAbbaGame();
+					}
+					sender.sendMessage("Game \"" + game.getName() + "\" " + (game.isOpen() ? "§aOpen":"§cClosed"));
+				}else{
+					sender.sendMessage(Messages.noPermissionError);
+					return false;
+				}
 				break;
+			case "list":
+				if(sender.hasPermission("AbbaCaving.list")){
+					sender.sendMessage("Games:");
+					for(AbbaGame g:AbbaTools.getGames()){
+						if(g.isOpen()){
+							sender.sendMessage("- §a" + g.getName());
+						}else{
+							sender.sendMessage("- §7§o" + g.getName());
+						}
+					}
+					return true;
+				}else{
+					sender.sendMessage(Messages.noPermissionError);
+					return false;
+				}
 			case "calc":
 				if(sender.hasPermission("AbbaCaving.calc")){
 					Player calcPlayer;
@@ -106,7 +145,7 @@ public class Main extends JavaPlugin{
 						}
 					}
 					
-					calculatedScore score = AbbaGame.calcScore(calcPlayer.getInventory());
+					calculatedScore score = AbbaTools.calcScore(calcPlayer.getInventory());
 					for(int i = 0; i < score.size(); i++){
 						if(score.getItemCount(i) != 0)
 							sender.sendMessage(score.getItemCount(i) + "x" + score.getItemStack(i).getType().toString() + ": " + score.getItemPoints(i));
@@ -115,7 +154,7 @@ public class Main extends JavaPlugin{
 					
 					
 				}else{
-					sender.sendMessage("§cYou don't have permission to use this command!");
+					sender.sendMessage(Messages.noPermissionError);
 					return false;
 				}
 				
@@ -138,7 +177,7 @@ public class Main extends JavaPlugin{
 					if(args.length >= 2){
 						gameName = args[1];
 					}else{
-						DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH:mm");
+						DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
 						gameName = "Abba" + dateFormat.format(new Date());
 						
 					}
@@ -173,15 +212,32 @@ public class Main extends JavaPlugin{
 					}
 					
 					
-					
-					AbbaGame abbaGame = new AbbaGame(gameSpawn, gameName);
-					
+					//create game
+					AbbaTools.create(gameName, gameSpawn, config.getInt("GameDuration"));
+					sender.sendMessage("Successfully created game \"" + gameName + "\"");
+					return true;
 					
 				}
 				break;
 			case "remove":
+				if(sender.hasPermission("AbbaCaving.remove")){
+					if(args.length >= 2){
+						if(AbbaTools.removeAbbaGame(args[1])){
+							sender.sendMessage("Successfully removed game \"" + args[1] + "\"");
+							return true;
+						}else{
+							sender.sendMessage("§cNo such game \"" + args[1] + "\"");
+							return false;
+						}
+					}else{
+						sender.sendMessage("Usage: /abba remove <game>");
+						return false;
+					}
+				}else{
+					sender.sendMessage(Messages.noPermissionError);
+					return false;
+				}
 				
-				break;
 			
 			
 			

+ 5 - 0
src/me/lennartVH01/Messages.java

@@ -0,0 +1,5 @@
+package me.lennartVH01;
+
+public class Messages {
+	public static final String noPermissionError = "§cYou don't have permission to use this command!";
+}