commit f185a37f35cd0985fc29bd71449196d914dde71e Author: headhunter45 Date: Tue Aug 9 01:46:34 2011 -0700 initial import diff --git a/MobScores/License-Header.txt b/MobScores/License-Header.txt new file mode 100644 index 0000000..9d44058 --- /dev/null +++ b/MobScores/License-Header.txt @@ -0,0 +1,17 @@ +/* +This file is part of MobScores. + +MobScores is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +MobScores is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with MobScores. If not, see . +*/ + diff --git a/MobScores/Manifest.MF b/MobScores/Manifest.MF new file mode 100644 index 0000000..58630c0 --- /dev/null +++ b/MobScores/Manifest.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/MobScores/MobScores.jardesc b/MobScores/MobScores.jardesc new file mode 100644 index 0000000..21be875 --- /dev/null +++ b/MobScores/MobScores.jardesc @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/MobScores/Readme.txt b/MobScores/Readme.txt new file mode 100644 index 0000000..83d90be --- /dev/null +++ b/MobScores/Readme.txt @@ -0,0 +1,6 @@ +This mod is copyright (c) 2011 Tom Hicks and released under the AGPL v3. See the file agpl-3.0.txt for the specifics of the license. + +No Commands + +Edit plugins/MobScores/config.yml to set scores per mob. + diff --git a/MobScores/bin/com/majinnaibu/bukkit/plugins/mobscores/MobScoresPlugin.class b/MobScores/bin/com/majinnaibu/bukkit/plugins/mobscores/MobScoresPlugin.class new file mode 100644 index 0000000..db2b5cf Binary files /dev/null and b/MobScores/bin/com/majinnaibu/bukkit/plugins/mobscores/MobScoresPlugin.class differ diff --git a/MobScores/bin/com/majinnaibu/bukkit/plugins/mobscores/listeners/MobDeathListener.class b/MobScores/bin/com/majinnaibu/bukkit/plugins/mobscores/listeners/MobDeathListener.class new file mode 100644 index 0000000..73bc03d Binary files /dev/null and b/MobScores/bin/com/majinnaibu/bukkit/plugins/mobscores/listeners/MobDeathListener.class differ diff --git a/MobScores/bin/com/majinnaibu/bukkit/plugins/mobscores/listeners/PlayerConnectListener.class b/MobScores/bin/com/majinnaibu/bukkit/plugins/mobscores/listeners/PlayerConnectListener.class new file mode 100644 index 0000000..0490e60 Binary files /dev/null and b/MobScores/bin/com/majinnaibu/bukkit/plugins/mobscores/listeners/PlayerConnectListener.class differ diff --git a/MobScores/bin/plugin.yml b/MobScores/bin/plugin.yml new file mode 100644 index 0000000..f1cf6e4 --- /dev/null +++ b/MobScores/bin/plugin.yml @@ -0,0 +1,4 @@ +name: MobScores +main: com.majinnaibu.bukkit.plugins.mobscores.MobScoresPlugin +depend: [ScoreKeeper] +version: 0.1 diff --git a/MobScores/src/com/majinnaibu/bukkit/plugins/mobscores/MobScoresPlugin.java b/MobScores/src/com/majinnaibu/bukkit/plugins/mobscores/MobScoresPlugin.java new file mode 100644 index 0000000..4d2fd45 --- /dev/null +++ b/MobScores/src/com/majinnaibu/bukkit/plugins/mobscores/MobScoresPlugin.java @@ -0,0 +1,163 @@ +/* +This file is part of MobScores. + +MobScores is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +MobScores is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with MobScores. If not, see . +*/ + +package com.majinnaibu.bukkit.plugins.mobscores; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.logging.Logger; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Zombie; +import org.bukkit.event.Event; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.util.config.Configuration; + +import com.majinnaibu.bukkit.plugins.mobscores.listeners.MobDeathListener; +import com.majinnaibu.bukkit.plugins.mobscores.listeners.PlayerConnectListener; +import com.majinnaibu.bukkit.plugins.scorekeeper.ScoreKeeperPlugin; + +public class MobScoresPlugin extends JavaPlugin { + private final MobDeathListener _mobDeathListener = new MobDeathListener(this); + private final PlayerConnectListener _playerConnectListener = new PlayerConnectListener(this); + private HashMap _claimedMobs = new HashMap(); + private HashMap _scoreTable = new HashMap(); + private ScoreKeeperPlugin _scoreKeeper = null; + private Configuration _configuration = null; + + private final String _logStart = "[" + ChatColor.AQUA + "MobScores" + ChatColor.WHITE + "] "; + + public final Logger log = Logger.getLogger("Minecraft"); + + @Override + public void onDisable() { + _configuration.setProperty("ScoreTable", _scoreTable); + _configuration.save(); + + } + + @SuppressWarnings("unchecked") + @Override + public void onEnable() { + _configuration = getConfiguration(); + try{ + _scoreTable = (HashMap)_configuration.getProperty("ScoreTable"); + }catch (Exception ex){ + _scoreTable = getDefaultScoreTable(); + } + + if(_scoreTable == null){ + _scoreTable = getDefaultScoreTable(); + } + + _configuration.setProperty("ScoreTable", _scoreTable); + + + _configuration.save(); + + PluginManager pm = getServer().getPluginManager(); + _scoreKeeper = (ScoreKeeperPlugin)pm.getPlugin("ScoreKeeper"); + + if(_scoreKeeper == null){ + pm.disablePlugin(this); + } + + pm.registerEvent(Event.Type.ENTITY_DEATH, _mobDeathListener, Event.Priority.Monitor, this); + pm.registerEvent(Event.Type.ENTITY_DAMAGE, _mobDeathListener, Event.Priority.Monitor, this); + pm.registerEvent(Event.Type.PLAYER_JOIN, _playerConnectListener, Event.Priority.Monitor, this); + + PluginDescriptionFile pdFile = this.getDescription(); + log.info(pdFile.getName() + " version " + pdFile.getVersion() + " is enabled!"); + } + + private HashMap getDefaultScoreTable() { + HashMap scores = new HashMap(); + + scores.put("org.bukkit.craftbukkit.entity.CraftZombie", 50); + scores.put("org.bukkit.craftbukkit.entity.CraftChicken", 0); + scores.put("org.bukkit.craftbukkit.entity.CraftCow", 0); + scores.put("org.bukkit.craftbukkit.entity.CraftCreeper", 50); + scores.put("org.bukkit.craftbukkit.entity.CraftGhast", 100); + scores.put("org.bukkit.craftbukkit.entity.CraftGiant", 250); + scores.put("org.bukkit.craftbukkit.entity.CraftPig", 0); + scores.put("org.bukkit.craftbukkit.entity.CraftPigZombie", 25); + scores.put("org.bukkit.craftbukkit.entity.CraftPlayer", 0); + scores.put("org.bukkit.craftbukkit.entity.CraftSheep", 0); + scores.put("org.bukkit.craftbukkit.entity.CraftSkeleton", 50); + scores.put("org.bukkit.craftbukkit.entity.CraftSlime", 100); + scores.put("org.bukkit.craftbukkit.entity.CraftSpider", 50); + scores.put("org.bukkit.craftbukkit.entity.CraftSquid", 0); + scores.put("org.bukkit.craftbukkit.entity.CraftWolf", 50); + scores.put("org.bukkit.craftbukkit.entity.CraftZombie", 50); + + return scores; + } + + public void claimMob(Entity entity, Player damager) { + if(entity instanceof Zombie){ + _claimedMobs.put((Zombie)entity, damager); + } + + } + + public void awardScore(Entity entity) { + // TODO Auto-generated method stub + + if(_claimedMobs.containsKey(entity)){ + Class scoreClass = entity.getClass(); + String className = scoreClass.getName(); + if(_scoreTable.containsKey(className)){ + Player player = _claimedMobs.get(entity); + int score = _scoreTable.get(className); + + _scoreKeeper.addScore(player, score); + }else{ + log.warning("[MobScores] Unable to award score for {" + className + "}"); + Set keys = _scoreTable.keySet(); + String str = null; + for(Iterator i = keys.iterator(); i.hasNext(); str = i.next()){ + log.info("{" + str + "}"); + } + } + } + } + + public void sendPlayerScoreTable(Player player) { + Iterator> i=_scoreTable.entrySet().iterator(); + Map.Entry pair = null; + for(pair = i.next(); i.hasNext(); pair = i.next()){ + if(pair.getValue() != 0){ + String key = pair.getKey(); + if(key.startsWith("org.bukkit.craftbukkit.entity.Craft")){ + player.sendMessage(_logStart + key.substring(35) + " = " + pair.getValue().toString()); + }else{ + player.sendMessage(_logStart + key + " = " + pair.getValue().toString()); + } + } + } + } + + public void logInfo(String string) { + log.info(_logStart + string); + } +} diff --git a/MobScores/src/com/majinnaibu/bukkit/plugins/mobscores/listeners/MobDeathListener.java b/MobScores/src/com/majinnaibu/bukkit/plugins/mobscores/listeners/MobDeathListener.java new file mode 100644 index 0000000..b892b5f --- /dev/null +++ b/MobScores/src/com/majinnaibu/bukkit/plugins/mobscores/listeners/MobDeathListener.java @@ -0,0 +1,57 @@ +/* +This file is part of MobScores. + +MobScores is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +MobScores is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with MobScores. If not, see . +*/ + +package com.majinnaibu.bukkit.plugins.mobscores.listeners; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityListener; + +import com.majinnaibu.bukkit.plugins.mobscores.MobScoresPlugin; + +public class MobDeathListener extends EntityListener { + private MobScoresPlugin _plugin = null; + + public MobDeathListener(MobScoresPlugin plugin) { + _plugin = plugin; + } + + @Override + public void onEntityDamage(EntityDamageEvent event) { + if(event instanceof EntityDamageByEntityEvent){ + EntityDamageByEntityEvent ev = (EntityDamageByEntityEvent) event; + Entity damager = ev.getDamager(); + if(damager instanceof Player){ + _plugin.claimMob(ev.getEntity(), (Player)damager); + } + } + } + + @Override + public void onEntityDeath(EntityDeathEvent event) { + _plugin.awardScore(event.getEntity()); + } + + @Override + public void onEntityExplode(EntityExplodeEvent event) { + } + +} diff --git a/MobScores/src/com/majinnaibu/bukkit/plugins/mobscores/listeners/PlayerConnectListener.java b/MobScores/src/com/majinnaibu/bukkit/plugins/mobscores/listeners/PlayerConnectListener.java new file mode 100644 index 0000000..486f7ed --- /dev/null +++ b/MobScores/src/com/majinnaibu/bukkit/plugins/mobscores/listeners/PlayerConnectListener.java @@ -0,0 +1,36 @@ +/* +This file is part of MobScores. + +MobScores is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +MobScores is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with MobScores. If not, see . +*/ + +package com.majinnaibu.bukkit.plugins.mobscores.listeners; + +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerListener; + +import com.majinnaibu.bukkit.plugins.mobscores.MobScoresPlugin; + +public class PlayerConnectListener extends PlayerListener { +private MobScoresPlugin _plugin = null; + + public PlayerConnectListener(MobScoresPlugin plugin) { + _plugin = plugin; + } + + @Override + public void onPlayerJoin(PlayerJoinEvent event) { + _plugin.sendPlayerScoreTable(event.getPlayer()); + } +} diff --git a/MobScores/src/plugin.yml b/MobScores/src/plugin.yml new file mode 100644 index 0000000..f1cf6e4 --- /dev/null +++ b/MobScores/src/plugin.yml @@ -0,0 +1,4 @@ +name: MobScores +main: com.majinnaibu.bukkit.plugins.mobscores.MobScoresPlugin +depend: [ScoreKeeper] +version: 0.1