From f185a37f35cd0985fc29bd71449196d914dde71e Mon Sep 17 00:00:00 2001 From: headhunter45 Date: Tue, 9 Aug 2011 01:46:34 -0700 Subject: [PATCH] initial import --- MobScores/License-Header.txt | 17 ++ MobScores/Manifest.MF | 2 + MobScores/MobScores.jardesc | 19 ++ MobScores/Readme.txt | 6 + .../plugins/mobscores/MobScoresPlugin.class | Bin 0 -> 8064 bytes .../listeners/MobDeathListener.class | Bin 0 -> 1756 bytes .../listeners/PlayerConnectListener.class | Bin 0 -> 1022 bytes MobScores/bin/plugin.yml | 4 + .../plugins/mobscores/MobScoresPlugin.java | 163 ++++++++++++++++++ .../mobscores/listeners/MobDeathListener.java | 57 ++++++ .../listeners/PlayerConnectListener.java | 36 ++++ MobScores/src/plugin.yml | 4 + 12 files changed, 308 insertions(+) create mode 100644 MobScores/License-Header.txt create mode 100644 MobScores/Manifest.MF create mode 100644 MobScores/MobScores.jardesc create mode 100644 MobScores/Readme.txt create mode 100644 MobScores/bin/com/majinnaibu/bukkit/plugins/mobscores/MobScoresPlugin.class create mode 100644 MobScores/bin/com/majinnaibu/bukkit/plugins/mobscores/listeners/MobDeathListener.class create mode 100644 MobScores/bin/com/majinnaibu/bukkit/plugins/mobscores/listeners/PlayerConnectListener.class create mode 100644 MobScores/bin/plugin.yml create mode 100644 MobScores/src/com/majinnaibu/bukkit/plugins/mobscores/MobScoresPlugin.java create mode 100644 MobScores/src/com/majinnaibu/bukkit/plugins/mobscores/listeners/MobDeathListener.java create mode 100644 MobScores/src/com/majinnaibu/bukkit/plugins/mobscores/listeners/PlayerConnectListener.java create mode 100644 MobScores/src/plugin.yml 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 0000000000000000000000000000000000000000..db2b5cff42aa646d3adc032fb6619b68201e134d GIT binary patch literal 8064 zcmbtZd0-URdH;Q4#SE(fgg9&&Fd|?qtq^Nt8*El!gd{*92^oP1U@VWMku+$vEB3%v zoZC5U=V}r=32xfNP8-^$O>7E_aax-+P2Hw#>a^*7=V)`^r{mc9y*IPFv(jQV&Oftn zzWLtwzW4ji_x7_dJoyxWjgmD`CD=TioQzJ|$K6E2c89Xjq3pzjn~6@vvtw=|9i2=L zrH7L#Cmroc4)yC%pZ;VZBv_qHjg`)b9=A{0(LH>4Y=T9Dl+oeXnelEnopBOQO3=|= z>8f#mj$Xe+N=&e9a4K$3JE`_$BH;{Yit@W&hWx&AqPU1PI2^a#NoRxrqy>w+^$xQc zHy+(>r^kEjDKgFL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giN(jMTH7#_^4UhhO}hN-7~8J6q_z;EiPseY=(sv6PpR4R|Ay*uB__H}k&z ztu)(xyp_ElSvNJKo0NH_}$KwP8bUKo%ivp#Ybhc+)VtI;t{!pc+a8Ct7Qu@ z4N>v}iAgI{R0p~vWe`H-M$Uu6jDvv(;l>48q*%>UGE_#-My#r z!IlfstKd@xJB54s$~zy0W~e^2SPtZ5;1pV$RpO$Q{a)g#57n;8$q{XdJNOL9xYM)e z1+lA`L~fil@p5yDx^bj!X%}tjm8AEuK)jcQ^g-sqhnNH3$6$Ovv*HJsl^$lmJ&31x zMX5^Cjo$VPwtHGzhg|^9X#7<Jt;~35G9IoU4F5oNND?axdasn@ n)Qp#8GC`qL5|>H-UWGYqNE0$OmzTG4Lekso@eqGA+v|S`U2FNl literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..73bc03d7767f18e57ea8b3cd2c5e2f808967f660 GIT binary patch literal 1756 zcmbVMT~pIQ6g{^s1WHN;r6M09ppd4}2#AP9AF%jTkQto5I@^*dfwp1N6y-!{m^Gtp)m*b`IyGb4E@VyN9^{%U3L=C#+bOl2%@ecg8vM81 zQ)A0}wQLE>2OpcTp6iyI8TULDyPm8Jp?AZoTJCGYhIVU|WS$UtWAB?$gfXB(fl3H# z$$UQugDQH^ONi&Js<~6I6iny6D3ndYaLz7@a$Y!=oHrLE?txV!WV;sg?{v!OS}7W| ztA75nq9RI6p4M_VC)zjMk`>4#^9t@0mb&rSJoSk@&nOajpkfT;glNfheNcxmp(O+S zoh8mFm?VsLlKI=aWpQdc5_3w$BZ=A1m_A(;GkC0EmaulqW>E12bA-NPSy&Zr6h;c> zD4_8g^}ak#7NN)MTtX^fcD0*3lS~MiCxn%*Tmo6m~}$M!Xf))~Dk#pG$%fgum+Fv}}b&SojZNz=4C=v+GXLd~3;*J@WU>mOd0G z0@HjQg!#(kO3OQezasptppVCXp1tGs5WnO4cSLpihM1n>;R`Q?5a)529l$UVOtHfZ z1~H2}ypr(UFvJ$}7sp+OCw}f>qzV3+sin7;xVUKmplRD2rHK<53i;hvGFpspyuKT!cc8zy5W>qoH);en&VudLzFy5kv zO7py(hS8LkWfK{Ec-p|qWzbP?Zy5tv=?GSB)2U3i#z=%0SZ^Y(GMYrBOBk6C Uu;FFCs0~33@zR6Hc#a!?0C)-5P5=M^ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..0490e602e01eebe65b9f4fd404999f834d6f106a GIT binary patch literal 1022 zcmbVL+iuf95Iy6hHF4brN+}SMLJO26MOfkmp;Ww-i$I1}D#|Oe-BsAu*+sro>SrNA zk$B((_$b7z?N9;|M75>y&hE@PvuDQNe|-H0;2}0`ScDgm9(&{9P%0J3F!#dz=tySX zhd3Wem3m_xrjbrW>cuk6gc3>W?Zv@~NOrVRBFg+~+eV$RsguzJK^zNZa7=8KGKnSF z?@9u~V}I5HUh8nbC}ppxZ9tgcmP%$%2;1Frqx6P^`i?#j4r*9%VZ$ZVy1iioge4bq zm?t!Ssl=On9E#*^5XOSA?CU6qhe0BZUv1X2_cA5CoVl3)XlkxF(aF`S)cuu~ig3T{ z|66Ml_RO?k&>K3qit9G65$?^H{oIZWVVt. +*/ + +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