forked from devtoi/BukkitMon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
725 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.settings | ||
bin | ||
.classpath | ||
.project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.toi.bukkitmon; | ||
|
||
import org.bukkit.entity.MobType; | ||
|
||
public class BMMob { | ||
|
||
private byte nrOfMobs = 1; | ||
private MobType mobtype = MobType.CHICKEN; | ||
private boolean rndAmount = false; | ||
private boolean rndType = false; | ||
private boolean active = true; | ||
private byte maxAmount = 10; | ||
|
||
public BMMob() | ||
{ | ||
|
||
} | ||
|
||
public boolean isRndAmount() { | ||
return rndAmount; | ||
} | ||
|
||
public void setRndAmount(boolean rndAmount) { | ||
this.rndAmount = rndAmount; | ||
} | ||
|
||
public boolean isRndType() { | ||
return rndType; | ||
} | ||
|
||
public void setRndType(boolean rndType) { | ||
this.rndType = rndType; | ||
} | ||
|
||
public byte getNrOfMobs() { | ||
return nrOfMobs; | ||
} | ||
|
||
public void setNrOfMobs(byte nrOfMobs) { | ||
this.nrOfMobs = nrOfMobs; | ||
} | ||
|
||
public MobType getMobtype() { | ||
return mobtype; | ||
} | ||
|
||
public void setMobtype(MobType mobtype) { | ||
this.mobtype = mobtype; | ||
} | ||
|
||
public boolean isActive() { | ||
return active; | ||
} | ||
|
||
public void setActive(boolean active) { | ||
this.active = active; | ||
} | ||
|
||
public byte getMaxAmount() { | ||
return maxAmount; | ||
} | ||
|
||
public void setMaxAmount(byte maxAmount) { | ||
this.maxAmount = maxAmount; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
package org.toi.bukkitmon; | ||
|
||
import java.io.IOException; | ||
import java.util.Hashtable; | ||
import java.util.Random; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.entity.MobType; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.player.PlayerChatEvent; | ||
import org.bukkit.event.player.PlayerEggThrowEvent; | ||
import org.bukkit.event.player.PlayerListener; | ||
import org.bukkit.plugin.Plugin; | ||
import org.toi.util.tPermissions; | ||
import org.toi.util.tProperties; | ||
|
||
public class BMPListener extends PlayerListener { | ||
|
||
private Plugin plugin; | ||
private Hashtable<String, BMMob> ph = new Hashtable<String, BMMob>(); | ||
private Random rnd = new Random(); | ||
private String bmStr = ChatColor.GOLD + "[BukkitMon] " + ChatColor.YELLOW; | ||
private tPermissions perms; | ||
private tProperties props; | ||
private boolean announce = true; | ||
private String announceString = ChatColor.RED + "SPAWNING --> Watch out! " + ChatColor.YELLOW + "<player>" + | ||
" spawned " + "<nr>" + " " + "<mobname>" + "s"; | ||
|
||
public BMPListener(BukkitMon plugin, tPermissions perms, tProperties props) | ||
{ | ||
this.plugin = plugin; | ||
this.perms = perms; | ||
this.props = props; | ||
} | ||
|
||
public void loadConfig() | ||
{ | ||
try { | ||
props.load(); | ||
BukkitMon.log.info("[BukkitMon] Config Loaded!"); | ||
} catch (IOException e) { | ||
BukkitMon.log.warning("[BukkitMon] Failed to load configuration: " | ||
+ e.getMessage()); | ||
} | ||
this.announce = props.getBoolean("announce-spawns", this.announce); | ||
this.announceString = props.getString("announce-tring", this.announceString); | ||
props.save(); | ||
} | ||
|
||
public void onPlayerEggThrow(PlayerEggThrowEvent event) | ||
{ | ||
Player player = event.getPlayer(); | ||
if (!ph.containsKey(player.getName())) | ||
ph.put(player.getName(), new BMMob()); | ||
BMMob bm = ph.get(player.getName()); | ||
if (bm.isActive()) | ||
{ | ||
MobType[] mts = MobType.values(); | ||
int rndint = rnd.nextInt(mts.length - 1); | ||
if (bm.isRndAmount()) | ||
event.setNumHatches((byte)rnd.nextInt(bm.getMaxAmount())); | ||
else | ||
event.setNumHatches(bm.getNrOfMobs()); | ||
if (bm.isRndType()) | ||
event.setHatchType(mts[rndint]); | ||
else | ||
event.setHatchType(bm.getMobtype()); | ||
event.setHatching(true); | ||
if (this.announce) | ||
{ | ||
String msg = this.announceString; | ||
try | ||
{ | ||
msg = msg.replace("<player>", player.getDisplayName()); | ||
msg = msg.replace("<nr>", String.valueOf(event.getNumHatches())); | ||
msg = msg.replace("<mobname>", event.getHatchType().getName()); | ||
} | ||
catch (NullPointerException npe){} | ||
this.plugin.getServer().broadcastMessage(msg); | ||
} | ||
} | ||
else | ||
event.setHatching(false); | ||
} | ||
|
||
public void onPlayerCommand(PlayerChatEvent event) | ||
{ | ||
Player player = event.getPlayer(); | ||
String[] split = event.getMessage().split(" "); | ||
if (split[0].equalsIgnoreCase("/bm")) | ||
{ | ||
if (split.length >= 2) | ||
{ | ||
if (!ph.containsKey(player.getName())) | ||
ph.put(player.getName(), new BMMob()); | ||
BMMob bm = ph.get(player.getName()); | ||
if (split[1].equalsIgnoreCase("mobs") && this.perms.canPlayerUseCommand(player.getName(), "mobs")) | ||
{ | ||
if (split.length >= 3) | ||
{ | ||
try{ | ||
byte val = Byte.valueOf(split[2]); | ||
if (val <= bm.getMaxAmount()) | ||
{ | ||
bm.setNrOfMobs(val); | ||
player.sendMessage(this.bmStr + "You set the number of mobs to spawn to: " + val); | ||
} | ||
else | ||
player.sendMessage(this.bmStr + val + " is more than the max amount"); | ||
} | ||
catch (NumberFormatException nfe){ | ||
player.sendMessage(this.bmStr + "You need to define a valid number"); | ||
} | ||
} | ||
else | ||
player.sendMessage(this.bmStr + "You need to define a number"); | ||
} | ||
else if (split[1].equalsIgnoreCase("mobtype") && this.perms.canPlayerUseCommand(player.getName(), "mobtype")) | ||
{ | ||
if (split.length >= 3) | ||
{ | ||
MobType mt = MobType.valueOf(split[2].toUpperCase()); | ||
if (mt != null) | ||
{ | ||
bm.setMobtype(mt); | ||
player.sendMessage(this.bmStr + "You set the mob type to " + split[2]); | ||
} | ||
else | ||
player.sendMessage(this.bmStr + "Invalid mobtype!"); | ||
} | ||
else | ||
player.sendMessage(this.bmStr + "You need to define a mobtype"); | ||
} | ||
else if (split[1].equalsIgnoreCase("randomamount") && this.perms.canPlayerUseCommand(player.getName(), "randomamount")) | ||
{ | ||
bm.setRndAmount(!bm.isRndAmount()); | ||
player.sendMessage(this.bmStr + "You set random amount to " + bm.isRndAmount()); | ||
} | ||
else if (split[1].equalsIgnoreCase("randomtype") && this.perms.canPlayerUseCommand(player.getName(), "randomtype")) | ||
{ | ||
bm.setRndType(!bm.isRndAmount()); | ||
player.sendMessage(this.bmStr + "You set random type to " + bm.isRndType()); | ||
} | ||
else if (split[1].equalsIgnoreCase("maxamount") && this.perms.canPlayerUseCommand(player.getName(), "maxamount")) | ||
{ | ||
if (split.length >= 3) | ||
{ | ||
try{ | ||
byte val = Byte.valueOf(split[2]); | ||
bm.setMaxAmount(val); | ||
player.sendMessage(this.bmStr + "You set the max amount of mobs to spawn to: " + val); | ||
} | ||
catch (NumberFormatException nfe){ | ||
player.sendMessage(this.bmStr + "You need to define a valid number"); | ||
} | ||
} | ||
else | ||
player.sendMessage(this.bmStr + "You need to define a number"); | ||
} | ||
else if (split[1].equalsIgnoreCase("activate") && this.perms.canPlayerUseCommand(player.getName(), "activate")) | ||
{ | ||
bm.setActive(!bm.isActive()); | ||
if (bm.isActive()) | ||
player.sendMessage(this.bmStr + "You activated BukkitMon"); | ||
else | ||
player.sendMessage(this.bmStr + "You deactivated BukkitMon"); | ||
|
||
} | ||
else if (split[1].equalsIgnoreCase("list") && this.perms.canPlayerUseCommand(player.getName(), "list")) | ||
{ | ||
player.sendMessage(ChatColor.RED + "BukkitMon commands:"); | ||
player.sendMessage(ChatColor.RED + "/bm mobs [#]" + ChatColor.YELLOW + " - Define how many mobs to spawn"); | ||
player.sendMessage(ChatColor.RED + "/bm mobtype [type]" + ChatColor.YELLOW + " - Define the mobtype to spawn"); | ||
player.sendMessage(ChatColor.RED + "/bm maxamount" + ChatColor.YELLOW + " - Defines the max amount of mobs you can spawn"); | ||
player.sendMessage(ChatColor.RED + "/bm randomamount" + ChatColor.YELLOW + " - Toggle random amount on/off"); | ||
player.sendMessage(ChatColor.RED + "/bm randomtype" + ChatColor.YELLOW + " - Toggle random mob type on/off"); | ||
player.sendMessage(ChatColor.RED + "/bm activate" + ChatColor.YELLOW + " - Activates the BukkitMon eggs"); | ||
player.sendMessage(ChatColor.RED + "/bm list" + ChatColor.YELLOW + " - Shows a list of avaliable BukkitMon commands"); | ||
} | ||
else | ||
player.sendMessage(this.bmStr + "Unknown BukkitMon command"); | ||
} | ||
else | ||
player.sendMessage(this.bmStr + "Define a function please!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.toi.bukkitmon; | ||
|
||
import java.io.File; | ||
import java.util.logging.Logger; | ||
|
||
import org.bukkit.Server; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.Event.Priority; | ||
import org.bukkit.plugin.PluginDescriptionFile; | ||
import org.bukkit.plugin.PluginLoader; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.toi.util.tPermissions; | ||
import org.toi.util.tProperties; | ||
|
||
public class BukkitMon extends JavaPlugin{ | ||
|
||
public static final Logger log = Logger.getLogger("Minecraft"); | ||
private String name = "BukkitMon"; | ||
private String version = "v0.2.1 (Ivysaur)"; | ||
private tPermissions perms = new tPermissions("BukkitMon" + File.separator + "bukkitmon.perms"); | ||
private tProperties props = new tProperties("BukkitMon" + File.separator + "bukkitmon.properties"); | ||
private final BMPListener playerListener = new BMPListener(this, perms, props); | ||
|
||
public BukkitMon(PluginLoader pluginLoader, Server instance, | ||
PluginDescriptionFile desc, File folder, File plugin, | ||
ClassLoader cLoader) { | ||
super(pluginLoader, instance, desc, folder, plugin, cLoader); | ||
this.registerEvents(); | ||
|
||
playerListener.loadConfig(); | ||
this.addCommands(); | ||
this.perms.loadPermissions(); | ||
this.perms.savePermissions(); | ||
} | ||
|
||
public void onDisable() { | ||
log.info(name + " " + version + " disabled!"); | ||
} | ||
|
||
public void onEnable() { | ||
log.info(name + " " + version + " enabled!"); | ||
} | ||
|
||
public void addCommands() | ||
{ | ||
perms.addCmd("mobs"); | ||
perms.addCmd("mobtype"); | ||
perms.addCmd("randomamount"); | ||
perms.addCmd("randomtype"); | ||
perms.addCmd("maxamount"); | ||
perms.addCmd("activate"); | ||
perms.addCmd("list"); | ||
} | ||
|
||
public void registerEvents() | ||
{ | ||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_EGG_THROW, playerListener, Priority.Normal, this); | ||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this); | ||
} | ||
|
||
} |
Oops, something went wrong.