Initial Import
This commit is contained in:
		| @@ -0,0 +1,65 @@ | |||||||
|  | package com.majinnaibu.bukkit.plugins.scorekeeper; | ||||||
|  |  | ||||||
|  | import java.util.HashMap; | ||||||
|  | import java.util.logging.Logger; | ||||||
|  |  | ||||||
|  | import org.bukkit.entity.Player; | ||||||
|  | import org.bukkit.plugin.PluginDescriptionFile; | ||||||
|  | import org.bukkit.plugin.java.JavaPlugin; | ||||||
|  |  | ||||||
|  | import com.majinnaibu.bukkit.plugins.scorekeeper.commands.ScoreAddCommand; | ||||||
|  | import com.majinnaibu.bukkit.plugins.scorekeeper.commands.ScoreArchiveCommand; | ||||||
|  | import com.majinnaibu.bukkit.plugins.scorekeeper.commands.ScoreGetCommand; | ||||||
|  | import com.majinnaibu.bukkit.plugins.scorekeeper.commands.ScoreResetCommand; | ||||||
|  | import com.majinnaibu.bukkit.plugins.scorekeeper.commands.ScoreSubtractCommand; | ||||||
|  |  | ||||||
|  | public class ScoreKeeperPlugin extends JavaPlugin { | ||||||
|  | 	private final HashMap<Player, Integer> _playerScores = new HashMap<Player, Integer>(); | ||||||
|  | 	 | ||||||
|  | 	public final Logger log = Logger.getLogger("Minecraft"); | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void onDisable() { | ||||||
|  | 		//TODO: save score data to file | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	@Override | ||||||
|  | 	public void onEnable() { | ||||||
|  | 		//PluginManager pm = getServer().getPluginManager(); | ||||||
|  | 		//pm.registerEvent(Event.Type.BLOCK_PHYSICS, new BlockListener(){}, Priority.Normal, this); | ||||||
|  | 		getCommand("score-get").setExecutor(new ScoreGetCommand(this)); | ||||||
|  | 		getCommand("score-add").setExecutor(new ScoreAddCommand(this)); | ||||||
|  | 		getCommand("score-subtract").setExecutor(new ScoreSubtractCommand(this)); | ||||||
|  | 		getCommand("score-reset").setExecutor(new ScoreResetCommand(this)); | ||||||
|  | 		getCommand("score-archive").setExecutor(new ScoreArchiveCommand(this)); | ||||||
|  |  | ||||||
|  | 		//TODO: load score data from file | ||||||
|  | 		 | ||||||
|  | 		PluginDescriptionFile pdFile = this.getDescription(); | ||||||
|  | 		log.info(pdFile.getName() + " version " + pdFile.getVersion() + " is enabled!"); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public int getPlayerScore(Player player) { | ||||||
|  | 		if(!_playerScores.containsKey(player)){ | ||||||
|  | 			_playerScores.put(player, 0); | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 		return _playerScores.get(player); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public void addScore(Player player, int amount) { | ||||||
|  | 		int score = getPlayerScore(player); | ||||||
|  | 		_playerScores.put(player,  score + amount); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public void subtractScore(Player player, int amount) { | ||||||
|  | 		int score = getPlayerScore(player); | ||||||
|  | 		_playerScores.put(player, score - amount); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public void resetPlayerScore(Player targetPlayer) { | ||||||
|  | 		// TODO Auto-generated method stub | ||||||
|  | 		 | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @@ -0,0 +1,75 @@ | |||||||
|  | package com.majinnaibu.bukkit.plugins.scorekeeper.commands; | ||||||
|  |  | ||||||
|  | import org.bukkit.ChatColor; | ||||||
|  | import org.bukkit.command.Command; | ||||||
|  | import org.bukkit.command.CommandExecutor; | ||||||
|  | import org.bukkit.command.CommandSender; | ||||||
|  | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
|  | import com.majinnaibu.bukkit.plugins.scorekeeper.ScoreKeeperPlugin; | ||||||
|  |  | ||||||
|  | public class ScoreAddCommand implements CommandExecutor { | ||||||
|  | 	private final ScoreKeeperPlugin _plugin; | ||||||
|  | 	 | ||||||
|  | 	public ScoreAddCommand(ScoreKeeperPlugin scoreKeeperPlugin) { | ||||||
|  | 		_plugin = scoreKeeperPlugin; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	@Override | ||||||
|  | 	public boolean onCommand( | ||||||
|  | 			CommandSender sender, | ||||||
|  | 			Command command, | ||||||
|  | 			String label, | ||||||
|  | 			String[] split | ||||||
|  | 	) { | ||||||
|  | 		boolean rcon = !(sender instanceof Player); | ||||||
|  | 		int amount = 0; | ||||||
|  | 		Player targetPlayer = null; | ||||||
|  | 		 | ||||||
|  | 		if(split.length == 1){ | ||||||
|  | 			if(rcon){ | ||||||
|  | 				echoUsage(sender, rcon); | ||||||
|  | 				return true; | ||||||
|  | 			}else{ | ||||||
|  | 				targetPlayer = (Player)sender; | ||||||
|  | 				try{ | ||||||
|  | 					amount = Integer.parseInt(split[0]); | ||||||
|  | 				}catch(NumberFormatException ex){ | ||||||
|  | 					echoError(sender, rcon, "amount must be an integer"); | ||||||
|  | 					return true; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		}else if(split.length == 2){ | ||||||
|  | 			targetPlayer = _plugin.getServer().getPlayer(split[0]); | ||||||
|  | 			if(targetPlayer == null){ | ||||||
|  | 				echoError(sender, rcon, "Can't find a player with that name"); | ||||||
|  | 				return true; | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
|  | 			try{ | ||||||
|  | 				amount = Integer.parseInt(split[1]); | ||||||
|  | 			}catch(NumberFormatException ex){ | ||||||
|  | 				echoError(sender, rcon, "amount must be an integer"); | ||||||
|  | 				return true; | ||||||
|  | 			} | ||||||
|  | 		}else{ | ||||||
|  | 			echoUsage(sender, rcon); | ||||||
|  | 			return true; | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 		_plugin.addScore(targetPlayer,  amount); | ||||||
|  | 		return true; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	private void echoError(CommandSender sender, boolean rcon, String string) { | ||||||
|  | 		sender.sendMessage("[" + ChatColor.RED + "ScoreKeeper" + ChatColor.WHITE + "] " + string); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	private void echoUsage(CommandSender sender, boolean rcon) { | ||||||
|  | 		if(rcon){ | ||||||
|  | 			sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": score-add " + ChatColor.GREEN + "<playername> <amount>"); | ||||||
|  | 		}else{ | ||||||
|  | 			sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-add " + ChatColor.YELLOW + "[playername] " + ChatColor.GREEN + "<amount>"); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @@ -0,0 +1,36 @@ | |||||||
|  | package com.majinnaibu.bukkit.plugins.scorekeeper.commands; | ||||||
|  |  | ||||||
|  | import org.bukkit.ChatColor; | ||||||
|  | import org.bukkit.command.Command; | ||||||
|  | import org.bukkit.command.CommandExecutor; | ||||||
|  | import org.bukkit.command.CommandSender; | ||||||
|  | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
|  | import com.majinnaibu.bukkit.plugins.scorekeeper.ScoreKeeperPlugin; | ||||||
|  |  | ||||||
|  | public class ScoreArchiveCommand implements CommandExecutor { | ||||||
|  | 	private final ScoreKeeperPlugin _plugin; | ||||||
|  | 	 | ||||||
|  | 	public ScoreArchiveCommand(ScoreKeeperPlugin scoreKeeperPlugin) { | ||||||
|  | 		_plugin = scoreKeeperPlugin; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	@Override | ||||||
|  | 	public boolean onCommand( | ||||||
|  | 			CommandSender sender, | ||||||
|  | 			Command command, | ||||||
|  | 			String label, | ||||||
|  | 			String[] split | ||||||
|  | 	) { | ||||||
|  | 		sender.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] archive command unimplemented "); | ||||||
|  | 		 | ||||||
|  | 		if(sender instanceof Player){ | ||||||
|  | 			Player player = (Player) sender; | ||||||
|  | 			int score = _plugin.getPlayerScore(player); | ||||||
|  | 			player.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] Your score is " + ChatColor.GREEN + score); | ||||||
|  | 			return true; | ||||||
|  | 		}else{ | ||||||
|  | 			return false; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @@ -0,0 +1,75 @@ | |||||||
|  | package com.majinnaibu.bukkit.plugins.scorekeeper.commands; | ||||||
|  |  | ||||||
|  | import org.bukkit.ChatColor; | ||||||
|  | import org.bukkit.command.Command; | ||||||
|  | import org.bukkit.command.CommandExecutor; | ||||||
|  | import org.bukkit.command.CommandSender; | ||||||
|  | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
|  | import com.majinnaibu.bukkit.plugins.scorekeeper.ScoreKeeperPlugin; | ||||||
|  |  | ||||||
|  | public class ScoreGetCommand implements CommandExecutor { | ||||||
|  | 	private final ScoreKeeperPlugin _plugin; | ||||||
|  | 	 | ||||||
|  | 	public ScoreGetCommand(ScoreKeeperPlugin scoreKeeperPlugin) { | ||||||
|  | 		_plugin = scoreKeeperPlugin; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	@Override | ||||||
|  | 	public boolean onCommand( | ||||||
|  | 			CommandSender sender, | ||||||
|  | 			Command command, | ||||||
|  | 			String label, | ||||||
|  | 			String[] split | ||||||
|  | 	) { | ||||||
|  | 		boolean rcon = !(sender instanceof Player); | ||||||
|  | 		Player targetPlayer = null; | ||||||
|  | 		 | ||||||
|  | 		if(split.length == 0){ | ||||||
|  | 			if(!rcon){ | ||||||
|  | 				targetPlayer = (Player)sender; | ||||||
|  | 			}else{ | ||||||
|  | 				echoUsage(sender, rcon); | ||||||
|  | 				return true; //false; | ||||||
|  | 			} | ||||||
|  | 		}else if(split.length == 1){ | ||||||
|  | 			targetPlayer = _plugin.getServer().getPlayer(split[0]); | ||||||
|  | 		}else if(split.length > 1){ | ||||||
|  | 			echoUsage(sender, rcon); | ||||||
|  | 			return true; //false; | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 		if(targetPlayer == null){ | ||||||
|  | 			echoError(sender, rcon, "Can't find a player with that name"); | ||||||
|  | 			return true; | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 		int score = _plugin.getPlayerScore(targetPlayer); | ||||||
|  | 		 | ||||||
|  | 		if(!rcon){ | ||||||
|  | 			if(sender == targetPlayer){ | ||||||
|  | 				targetPlayer.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] Your score is " + ChatColor.GREEN + score); | ||||||
|  | 			}else{ | ||||||
|  | 				sender.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] " + targetPlayer.getName() + "'s score is " + ChatColor.GREEN + score); | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
|  | 			return true; | ||||||
|  | 		}else{ | ||||||
|  | 			sender.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] " + targetPlayer.getName() + "'s score is " + ChatColor.GREEN + score); | ||||||
|  | 			return true; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	private void echoError(CommandSender sender, boolean rcon, String string) { | ||||||
|  | 		sender.sendMessage("[" + ChatColor.RED + "ScoreKeeper" + ChatColor.WHITE + "] " + string); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	private void echoUsage(CommandSender sender, boolean rcon) { | ||||||
|  | 		if(rcon){ | ||||||
|  | 			sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": score-get " + ChatColor.GREEN + "<playername>"); | ||||||
|  | 		}else{ | ||||||
|  | 			sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-get " + ChatColor.YELLOW + "[playername]"); | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 	}	 | ||||||
|  | } | ||||||
| @@ -0,0 +1,76 @@ | |||||||
|  | package com.majinnaibu.bukkit.plugins.scorekeeper.commands; | ||||||
|  |  | ||||||
|  | import org.bukkit.ChatColor; | ||||||
|  | import org.bukkit.command.Command; | ||||||
|  | import org.bukkit.command.CommandExecutor; | ||||||
|  | import org.bukkit.command.CommandSender; | ||||||
|  | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
|  | import com.majinnaibu.bukkit.plugins.scorekeeper.ScoreKeeperPlugin; | ||||||
|  |  | ||||||
|  | public class ScoreResetCommand implements CommandExecutor { | ||||||
|  | 	private final ScoreKeeperPlugin _plugin; | ||||||
|  | 	 | ||||||
|  | 	public ScoreResetCommand(ScoreKeeperPlugin scoreKeeperPlugin) { | ||||||
|  | 		_plugin = scoreKeeperPlugin; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	@Override | ||||||
|  | 	public boolean onCommand( | ||||||
|  | 			CommandSender sender, | ||||||
|  | 			Command command, | ||||||
|  | 			String label, | ||||||
|  | 			String[] split | ||||||
|  | 	) { | ||||||
|  | 		sender.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] archive command unimplemented "); | ||||||
|  | 	 | ||||||
|  | 		boolean rcon = !(sender instanceof Player); | ||||||
|  | 		Player targetPlayer = null; | ||||||
|  | 		 | ||||||
|  | 		if(split.length == 1){ | ||||||
|  | 			if(rcon){ | ||||||
|  | 				echoUsage(sender, rcon); | ||||||
|  | 				return true; | ||||||
|  | 			}else{ | ||||||
|  | 				targetPlayer = (Player)sender; | ||||||
|  | 				try{ | ||||||
|  | 					 | ||||||
|  | 				}catch(NumberFormatException ex){ | ||||||
|  | 					echoError(sender, rcon, "amount must be an integer"); | ||||||
|  | 					return true; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		}else if(split.length == 2){ | ||||||
|  | 			targetPlayer = _plugin.getServer().getPlayer(split[0]); | ||||||
|  | 			if(targetPlayer == null){ | ||||||
|  | 				echoError(sender, rcon, "Can't find a player with that name"); | ||||||
|  | 				return true; | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
|  | 			try{ | ||||||
|  | 				 | ||||||
|  | 			}catch(NumberFormatException ex){ | ||||||
|  | 				echoError(sender, rcon, "amount must be an integer"); | ||||||
|  | 				return true; | ||||||
|  | 			} | ||||||
|  | 		}else{ | ||||||
|  | 			echoUsage(sender, rcon); | ||||||
|  | 			return true; | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 		_plugin.resetPlayerScore(targetPlayer); | ||||||
|  | 		return true; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	private void echoError(CommandSender sender, boolean rcon, String string) { | ||||||
|  | 		sender.sendMessage("[" + ChatColor.RED + "ScoreKeeper" + ChatColor.WHITE + "] " + string); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	private void echoUsage(CommandSender sender, boolean rcon) { | ||||||
|  | 		if(rcon){ | ||||||
|  | 			sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": score-reset " + ChatColor.GREEN + "<playername>"); | ||||||
|  | 		}else{ | ||||||
|  | 			sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-reset " + ChatColor.YELLOW + "[playername]"); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @@ -0,0 +1,75 @@ | |||||||
|  | package com.majinnaibu.bukkit.plugins.scorekeeper.commands; | ||||||
|  |  | ||||||
|  | import org.bukkit.ChatColor; | ||||||
|  | import org.bukkit.command.Command; | ||||||
|  | import org.bukkit.command.CommandExecutor; | ||||||
|  | import org.bukkit.command.CommandSender; | ||||||
|  | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
|  | import com.majinnaibu.bukkit.plugins.scorekeeper.ScoreKeeperPlugin; | ||||||
|  |  | ||||||
|  | public class ScoreSubtractCommand implements CommandExecutor { | ||||||
|  | 	private final ScoreKeeperPlugin _plugin; | ||||||
|  | 	 | ||||||
|  | 	public ScoreSubtractCommand(ScoreKeeperPlugin scoreKeeperPlugin) { | ||||||
|  | 		_plugin = scoreKeeperPlugin; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	@Override | ||||||
|  | 	public boolean onCommand( | ||||||
|  | 			CommandSender sender, | ||||||
|  | 			Command command, | ||||||
|  | 			String label, | ||||||
|  | 			String[] split | ||||||
|  | 	) { | ||||||
|  | 		boolean rcon = !(sender instanceof Player); | ||||||
|  | 		int amount = 0; | ||||||
|  | 		Player targetPlayer = null; | ||||||
|  | 		 | ||||||
|  | 		if(split.length == 1){ | ||||||
|  | 			if(rcon){ | ||||||
|  | 				echoUsage(sender, rcon); | ||||||
|  | 				return true; | ||||||
|  | 			}else{ | ||||||
|  | 				targetPlayer = (Player)sender; | ||||||
|  | 				try{ | ||||||
|  | 					amount=Integer.parseInt(split[0]); | ||||||
|  | 				}catch(NumberFormatException ex){ | ||||||
|  | 					echoError(sender, rcon, "amount must be an integer"); | ||||||
|  | 					return true; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		}else if(split.length == 2){ | ||||||
|  | 			targetPlayer = _plugin.getServer().getPlayer(split[0]); | ||||||
|  | 			if(targetPlayer == null){ | ||||||
|  | 				echoError(sender, rcon, "Can't find a player with that name"); | ||||||
|  | 				return true; | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
|  | 			try{ | ||||||
|  | 				amount = Integer.parseInt(split[1]); | ||||||
|  | 			}catch(NumberFormatException ex){ | ||||||
|  | 				echoError(sender, rcon, "amount must be an integer"); | ||||||
|  | 				return true; | ||||||
|  | 			} | ||||||
|  | 		}else{ | ||||||
|  | 			echoUsage(sender, rcon); | ||||||
|  | 			return true; | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 		_plugin.subtractScore(targetPlayer, amount); | ||||||
|  | 		return true; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	private void echoError(CommandSender sender, boolean rcon, String string) { | ||||||
|  | 		sender.sendMessage("[" + ChatColor.RED + "ScoreKeeper" + ChatColor.WHITE + "] " + string); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	private void echoUsage(CommandSender sender, boolean rcon) { | ||||||
|  | 		if(rcon){ | ||||||
|  | 			sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": score-subtract " + ChatColor.GREEN + "<playername> <amount>"); | ||||||
|  | 		}else{ | ||||||
|  | 			sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-subtract " + ChatColor.YELLOW + "[playername] " + ChatColor.GREEN + "<amount>"); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										20
									
								
								ScoreKeeper/src/plugin.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								ScoreKeeper/src/plugin.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | |||||||
|  | name: ScoreKeeper | ||||||
|  | main: com.majinnaibu.bukkit.plugins.scorekeeper.ScoreKeeperPlugin | ||||||
|  | version: 0.0a | ||||||
|  | commands: | ||||||
|  |     score-get: | ||||||
|  |         description: Displays the player's score. | ||||||
|  |         usage: /score-get [playername] | ||||||
|  |     score-add: | ||||||
|  |         description: Adds point to the player's score. | ||||||
|  |         usage: /score-add [playername] <amount> | ||||||
|  |     score-subtract: | ||||||
|  |         description: Subtracts points from the player's score. | ||||||
|  |         usage: /score-subtract [playername] <amount> | ||||||
|  |     score-reset:  | ||||||
|  |         description: Resets the player's score | ||||||
|  |         usage: /score-reset [playername] | ||||||
|  |     score-archive: | ||||||
|  |         description: Archives and resets the player's score  | ||||||
|  |         usage: /score-archive [playername] | ||||||
|  |          | ||||||
		Reference in New Issue
	
	Block a user