commit 6815244bed962ebea897c8045f3af8596651779a Author: headhunter45 Date: Mon Jul 18 18:11:06 2011 -0700 Initial Import diff --git a/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/ScoreKeeperPlugin.java b/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/ScoreKeeperPlugin.java new file mode 100644 index 0000000..4d5349e --- /dev/null +++ b/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/ScoreKeeperPlugin.java @@ -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 _playerScores = new HashMap(); + + 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 + + } +} diff --git a/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreAddCommand.java b/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreAddCommand.java new file mode 100644 index 0000000..cc2a906 --- /dev/null +++ b/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreAddCommand.java @@ -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 + " "); + }else{ + sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-add " + ChatColor.YELLOW + "[playername] " + ChatColor.GREEN + ""); + } + } +} diff --git a/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreArchiveCommand.java b/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreArchiveCommand.java new file mode 100644 index 0000000..5638923 --- /dev/null +++ b/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreArchiveCommand.java @@ -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; + } + } +} diff --git a/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreGetCommand.java b/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreGetCommand.java new file mode 100644 index 0000000..30252d8 --- /dev/null +++ b/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreGetCommand.java @@ -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 + ""); + }else{ + sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-get " + ChatColor.YELLOW + "[playername]"); + } + + } +} diff --git a/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreResetCommand.java b/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreResetCommand.java new file mode 100644 index 0000000..7686d7e --- /dev/null +++ b/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreResetCommand.java @@ -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 + ""); + }else{ + sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-reset " + ChatColor.YELLOW + "[playername]"); + } + } +} diff --git a/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreSubtractCommand.java b/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreSubtractCommand.java new file mode 100644 index 0000000..fe0d508 --- /dev/null +++ b/ScoreKeeper/src/com/majinnaibu/bukkit/plugins/scorekeeper/commands/ScoreSubtractCommand.java @@ -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 + " "); + }else{ + sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-subtract " + ChatColor.YELLOW + "[playername] " + ChatColor.GREEN + ""); + } + } +} diff --git a/ScoreKeeper/src/plugin.yml b/ScoreKeeper/src/plugin.yml new file mode 100644 index 0000000..c894174 --- /dev/null +++ b/ScoreKeeper/src/plugin.yml @@ -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] + score-subtract: + description: Subtracts points from the player's score. + usage: /score-subtract [playername] + 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] + \ No newline at end of file