Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Eliot committed Dec 17, 2011
1 parent e4c6b3d commit c80849b
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 141 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
12 changes: 6 additions & 6 deletions src/org/bukkitmon/BMMob.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.bukkitmon;

import org.bukkit.entity.MobType;
import org.bukkit.entity.CreatureType;

public class BMMob {

private byte nrOfMobs = 1;
private MobType mobtype = MobType.CHICKEN;
private CreatureType creatureType = org.bukkit.entity.CreatureType.CHICKEN;
private boolean rndAmount = false;
private boolean rndType = false;
private boolean active = true;
Expand Down Expand Up @@ -40,12 +40,12 @@ public void setNrOfMobs(byte nrOfMobs) {
this.nrOfMobs = nrOfMobs;
}

public MobType getMobtype() {
return mobtype;
public CreatureType getCreatureType() {
return creatureType;
}

public void setMobtype(MobType mobtype) {
this.mobtype = mobtype;
public void setCreatureType(CreatureType creatureType) {
this.creatureType = creatureType;
}

public boolean isActive() {
Expand Down
164 changes: 81 additions & 83 deletions src/org/bukkitmon/BMPListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Random;

import org.bukkit.ChatColor;
import org.bukkit.entity.MobType;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerEggThrowEvent;
Expand Down Expand Up @@ -33,7 +33,7 @@ public void onPlayerEggThrow(PlayerEggThrowEvent event)
BMMob bm = ph.get(player.getName());
if (bm.isActive())
{
MobType[] mts = MobType.values();
CreatureType[] mts = CreatureType.values();
int rndint = rnd.nextInt(mts.length - 1);
if (bm.isRndAmount())
event.setNumHatches((byte)rnd.nextInt(bm.getMaxAmount()));
Expand All @@ -42,7 +42,7 @@ public void onPlayerEggThrow(PlayerEggThrowEvent event)
if (bm.isRndType())
event.setHatchType(mts[rndint]);
else
event.setHatchType(bm.getMobtype());
event.setHatchType(bm.getCreatureType());
event.setHatching(true);
this.plugin.getServer().broadcastMessage(ChatColor.RED + "SPAWNING --> Watch out! " + ChatColor.YELLOW + player.getDisplayName() +
" spawned " + event.getNumHatches() + " " + event.getHatchType().getName() + "s");
Expand All @@ -51,105 +51,103 @@ public void onPlayerEggThrow(PlayerEggThrowEvent event)
event.setHatching(false);
}

public void onPlayerCommand(PlayerChatEvent event)
public boolean onPlayerCommand(Player player, String[] split)
{
Player player = event.getPlayer();
String[] split = event.getMessage().split(" ");
if (split[0].equalsIgnoreCase("/bm"))
//Player player = event.getPlayer();
//String[] split = event.getMessage().split(" ");
if (split.length >= 1)
{
if (split.length >= 2)
if (!ph.containsKey(player.getName()))
ph.put(player.getName(), new BMMob());
BMMob bm = ph.get(player.getName());
if (split[0].equalsIgnoreCase("mobs") && this.perms.canPlayerUseCommand(player.getName(), "mobs"))
{
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 >= 2)
{
if (split.length >= 3)
{
MobType mt = MobType.valueOf(split[2].toUpperCase());
if (mt != null)
try{
byte val = Byte.valueOf(split[1]);
if (val <= bm.getMaxAmount())
{
bm.setMobtype(mt);
player.sendMessage(this.bmStr + "You set the mob type to " + split[2]);
bm.setNrOfMobs(val);
player.sendMessage(this.bmStr + "You set the number of mobs to spawn to: " + val);
}
else
player.sendMessage(this.bmStr + "Invalid mobtype!");
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 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("randommob") && this.perms.canPlayerUseCommand(player.getName(), "randommob"))
{
bm.setRndAmount(!bm.isRndAmount());
player.sendMessage(this.bmStr + "You set randommob to " + bm.isRndAmount());
}
else if (split[1].equalsIgnoreCase("maxamount") && this.perms.canPlayerUseCommand(player.getName(), "maxamount"))
else
player.sendMessage(this.bmStr + "You need to define a number");
}
else if (split[0].equalsIgnoreCase("CreatureType") && this.perms.canPlayerUseCommand(player.getName(), "CreatureType"))
{
if (split.length >= 2)
{
if (split.length >= 3)
CreatureType mt = CreatureType.valueOf(split[1].toUpperCase());
if (mt != null)
{
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");
}
bm.setCreatureType(mt);
player.sendMessage(this.bmStr + "You set the mob type to " + split[1]);
}
else
player.sendMessage(this.bmStr + "You need to define a number");
player.sendMessage(this.bmStr + "Invalid CreatureType!");
}
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"))
else
player.sendMessage(this.bmStr + "You need to define a CreatureType");
}
else if (split[0].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[0].equalsIgnoreCase("randommob") && this.perms.canPlayerUseCommand(player.getName(), "randommob"))
{
bm.setRndAmount(!bm.isRndAmount());
player.sendMessage(this.bmStr + "You set randommob to " + bm.isRndAmount());
}
else if (split[0].equalsIgnoreCase("maxamount") && this.perms.canPlayerUseCommand(player.getName(), "maxamount"))
{
if (split.length >= 2)
{
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 randommob" + 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");
try{
byte val = Byte.valueOf(split[1]);
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 + "Unknown BukkitMon command");
player.sendMessage(this.bmStr + "You need to define a number");
}
else if (split[0].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[0].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 CreatureType [type]" + ChatColor.YELLOW + " - Define the CreatureType 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 randommob" + 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 + "Define a function please!");
player.sendMessage(this.bmStr + "Unknown BukkitMon command");
}
else
player.sendMessage(this.bmStr + "Define a function please!");
return true;
}
}
18 changes: 16 additions & 2 deletions src/org/bukkitmon/BukkitMon.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import java.util.logging.Logger;

import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.plugin.PluginDescriptionFile;
Expand All @@ -21,7 +24,8 @@ public class BukkitMon extends JavaPlugin{
public BukkitMon(PluginLoader pluginLoader, Server instance,
PluginDescriptionFile desc, File folder, File plugin,
ClassLoader cLoader) {
super(pluginLoader, instance, desc, folder, plugin, cLoader);
super();
initialize(pluginLoader, instance, desc, folder, plugin, cLoader);
this.registerEvents();
this.addCommands();
this.perms.loadPermissions();
Expand Down Expand Up @@ -50,7 +54,17 @@ public void addCommands()
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);
//getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
}

public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
Player player=(Player) sender;
if (cmd.getName().equalsIgnoreCase("/bm"))
{
playerListener.onPlayerCommand(player, args);
return true;
}
return false;
}

}
18 changes: 12 additions & 6 deletions src/org/toi/bukkitmon/BMMob.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package org.toi.bukkitmon;

import org.bukkit.entity.MobType;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Player;

public class BMMob {

private byte nrOfMobs = 1;
private MobType mobtype = MobType.CHICKEN;
private CreatureType CreatureType = org.bukkit.entity.CreatureType.CHICKEN;
private boolean rndAmount = false;
private boolean rndType = false;
private boolean active = true;
Expand Down Expand Up @@ -40,12 +44,12 @@ public void setNrOfMobs(byte nrOfMobs) {
this.nrOfMobs = nrOfMobs;
}

public MobType getMobtype() {
return mobtype;
public CreatureType getCreatureType() {
return CreatureType;
}

public void setMobtype(MobType mobtype) {
this.mobtype = mobtype;
public void setCreatureType(CreatureType CreatureType) {
this.CreatureType = CreatureType;
}

public boolean isActive() {
Expand All @@ -64,4 +68,6 @@ public void setMaxAmount(byte maxAmount) {
this.maxAmount = maxAmount;
}



}
Loading

0 comments on commit c80849b

Please sign in to comment.