All changes up to 0.5.17

This commit is contained in:
nossr50 2011-02-16 14:27:59 -08:00
parent 3a95c2eeb6
commit ce5e1e5a3b
10 changed files with 3341 additions and 2 deletions

View File

@ -1,5 +1,16 @@
Changelog: Changelog:
#Versions without changelogs probably had very small misc fixes, like tweaks to the source code# #Versions without changelogs probably had very small misc fixes, like tweaks to the source code#
Version 0.5.17
Changed namespaces to fit bukkits new standard
Adjusted excavation proc rates
Modified excavation loot tables
Added Party Invite System
Version 0.5.16
Fixed unarmed not checking for permissions when hitting players
Version 0.5.15 Version 0.5.15
Fixed stone swords not being recognized as swords Fixed stone swords not being recognized as swords
Fixed /a not working if you were an op but did not have permissions Fixed /a not working if you were an op but did not have permissions

View File

@ -0,0 +1,111 @@
package com.gmail.nossr50;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
public class mcBlockListener extends BlockListener {
private final mcMMO plugin;
public mcBlockListener(final mcMMO plugin) {
this.plugin = plugin;
}
public void onBlockPlace(BlockPlaceEvent event) {
Block block = event.getBlock();
int x = block.getX();
int y = block.getY();
int z = block.getZ();
String xyz = x+","+y+","+z;
mcConfig.getInstance().addBlockWatch(block);
mcConfig.getInstance().addCoordsWatch(xyz);
if(block.getTypeId() == 42)
event.getPlayer().sendMessage(ChatColor.DARK_RED+"You have placed an anvil, anvils can repair tools and armor.");
}
//put all Block related code here
public void onBlockDamage(BlockDamageEvent event) {
//STARTED(0), DIGGING(1), BROKEN(3), STOPPED(2);
Player player = event.getPlayer();
Block block = event.getBlock();
int x = block.getX();
int y = block.getY();
int z = block.getZ();
String xyz = x+","+y+","+z;
int type = block.getTypeId();
Location loc = block.getLocation();
int dmg = event.getDamageLevel().getLevel();
/*
* MINING
*/
if(dmg == 3 && !mcConfig.getInstance().isBlockWatched(block) && !mcConfig.getInstance().isCoordsWatched(xyz)){
if(mcPermissions.getInstance().mining(player))
mcm.getInstance().miningBlockCheck(player, block);
/*
* WOOD CUTTING
*/
if(block.getTypeId() == 17
&& mcPermissions.getInstance().woodcutting(player)){
mcUsers.getProfile(player).addwgather(1);
mcm.getInstance().woodCuttingProcCheck(player, block, loc);
}
mcm.getInstance().simulateSkillUp(player);
/*
* EXCAVATION
*/
if(mcPermissions.getInstance().excavation(player))
mcm.getInstance().excavationProcCheck(block, player);
/*
* HERBALISM
*/
if(!(type == 39 || type == 40 || type == 37 || type == 38)
&& mcPermissions.getInstance().herbalism(player));
mcm.getInstance().herbalismProcCheck(block, player); //You place the blocks so we wont check if they are being watched
/*
* EXPLOIT COUNTERMEASURES
*/
mcConfig.getInstance().addCoordsWatch(xyz);
mcConfig.getInstance().addBlockWatch(block);
}
}
public void onBlockFlow(BlockFromToEvent event) {
//Code borrowed from WorldGuard by sk89q
World world = event.getBlock().getWorld();
int radius = 1;
Block blockFrom = event.getBlock();
Block blockTo = event.getToBlock();
boolean isWater = blockFrom.getTypeId() == 8 || blockFrom.getTypeId() == 9;
int ox = blockTo.getX();
int oy = blockTo.getY();
int oz = blockTo.getZ();
if(blockTo.getTypeId() == 9 || blockTo.getTypeId() == 8){
return;
}
for (int cx = -radius; cx <= radius; cx++) {
for (int cy = -radius; cy <= radius; cy++) {
for (int cz = -radius; cz <= radius; cz++) {
Block dirt = world.getBlockAt(ox + cx, oy + cy, oz + cz);
//If block is dirt
if (isWater == true &&
dirt.getTypeId() == 13) {
//Change
dirt.setTypeId(82);
return;
}
}
}
}
}
}

View File

@ -0,0 +1,96 @@
package com.gmail.nossr50;
import java.util.ArrayList;
import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class mcConfig {
private static volatile mcConfig instance;
String location = "mcmmo.properties";
protected static final Logger log = Logger.getLogger("Minecraft");
static ArrayList<String> adminChatList = new ArrayList<String>();
static ArrayList<String> coordsWatchList = new ArrayList<String>();
static ArrayList<Block> blockWatchList = new ArrayList<Block>();
static ArrayList<String> partyChatList = new ArrayList<String>();
public boolean isBlockWatched(Block block) {return blockWatchList.contains(block);}
public boolean isCoordsWatched(String xyz) {return coordsWatchList.contains(xyz);}
public void removeBlockWatch(Block block) {blockWatchList.remove(blockWatchList.indexOf(block));}
public void removeCoordsWatch(String xyz) {coordsWatchList.remove(coordsWatchList.indexOf(xyz));}
public void addBlockWatch(Block block) {blockWatchList.add(block);}
public void addCoordsWatch(String xyz) {coordsWatchList.add(xyz);}
public boolean isAdminToggled(String playerName) {return adminChatList.contains(playerName);}
public boolean isPartyToggled(String playerName) {return partyChatList.contains(playerName);}
public void removePartyToggled(String playerName) {partyChatList.remove(partyChatList.indexOf(playerName));}
public void removeAdminToggled(String playerName) {adminChatList.remove(adminChatList.indexOf(playerName));}
public void addPartyToggled(String playerName) {partyChatList.add(playerName);}
public void addAdminToggled(String playerName) {adminChatList.add(playerName);}
public static mcConfig getInstance() {
if (instance == null) {
instance = new mcConfig();
}
return instance;
}
public void toggleAdminChat(String playerName){
if(isAdminToggled(playerName)){
removeAdminToggled(playerName);
} else {
addAdminToggled(playerName);
}
}
public void togglePartyChat(String playerName){
if(isPartyToggled(playerName)){
removePartyToggled(playerName);
} else {
addPartyToggled(playerName);
}
}
public void woodProcChecks(Player player, Block block, Location loc){
if(mcUsers.getProfile(player).getWoodCuttingint() > 1000){
Material mat = Material.getMaterial(block.getTypeId());
byte damage = 0;
ItemStack item = new ItemStack(mat, 1, (byte)0, damage);
block.getWorld().dropItemNaturally(loc, item);
return;
}
if(mcUsers.getProfile(player).getWoodCuttingint() > 750){
if((Math.random() * 10) > 2){
Material mat = Material.getMaterial(block.getTypeId());
byte damage = 0;
ItemStack item = new ItemStack(mat, 1, (byte)0, damage);
block.getWorld().dropItemNaturally(loc, item);
return;
}
}
if(mcUsers.getProfile(player).getWoodCuttingint() > 300){
if((Math.random() * 10) > 4){
Material mat = Material.getMaterial(block.getTypeId());
byte damage = 0;
ItemStack item = new ItemStack(mat, 1, (byte)0, damage);
block.getWorld().dropItemNaturally(loc, item);
return;
}
}
if(mcUsers.getProfile(player).getWoodCuttingint() > 100){
if((Math.random() * 10) > 6){
Material mat = Material.getMaterial(block.getTypeId());
byte damage = 0;
ItemStack item = new ItemStack(mat, 1, (byte)0, damage);
block.getWorld().dropItemNaturally(loc, item);
return;
}
}
if(mcUsers.getProfile(player).getWoodCuttingint() > 10){
if((Math.random() * 10) > 8){
Material mat = Material.getMaterial(block.getTypeId());
byte damage = 0;
ItemStack item = new ItemStack(mat, 1, (byte)0, damage);
block.getWorld().dropItemNaturally(loc, item);
return;
}
}
}
}

View File

@ -0,0 +1,376 @@
package com.gmail.nossr50;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Spider;
import org.bukkit.entity.Squid;
import org.bukkit.entity.Zombie;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.inventory.ItemStack;
public class mcEntityListener extends EntityListener {
private final mcMMO plugin;
public mcEntityListener(final mcMMO plugin) {
this.plugin = plugin;
}
public void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
Block block = event.getDamager();
Entity x = event.getEntity();
if(x instanceof Player){
Player player = (Player)x;
if(block != null && block.getTypeId() == 81){
if(mcUsers.getProfile(player).isDead())
return;
/*
if(player.getHealth() - event.getDamage() <= 0){
mcUsers.getProfile(player).setDead(true);
for(Player bidoof : plugin.getServer().getOnlinePlayers()){
bidoof.sendMessage(ChatColor.GRAY+player.getName()+" has been"+ChatColor.DARK_GREEN+" cactus tickled "+ChatColor.GRAY+"to death.");
}
}
*/
}
}
}
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity x = event.getEntity(); //Defender
Entity y = event.getDamager(); //Attacker
/*
* IF DEFENDER IS PLAYER
*/
if(x instanceof Player){
Player defender = (Player)x;
/*
* PARRYING CHECK, CHECK TO SEE IF ITS A SUCCESSFUL PARRY OR NOT
*/
mcm.getInstance().parryCheck(defender, event, y);
/*
* PLAYER DEATH BY MONSTER MESSAGE CHECK, CHECKS TO SEE IF TO REPORT THE DEATH OR NOT
*/
mcm.getInstance().playerDeathByMonsterMessageCheck(y, defender, plugin);
/*
* CHECKS IF THE PLAYER DIES, IF SO DROP HIS SHIT BECAUSE OF THE DAMAGE MODIFIERS
* MIGHT BE A BIT BUGGY, IT SEEMS TO WORK RIGHT NOW AT LEAST...
*/
}
/*
* IF ATTACKER IS PLAYER
*/
if(y instanceof Player){
int type = ((Player) y).getItemInHand().getTypeId();
Player attacker = (Player)y;
/*
* Player versus Monster checks, this handles all skill damage modifiers and any procs.
*/
mcm.getInstance().playerVersusMonsterChecks(event, attacker, x, type);
/*
* Player versus Squid checks, this handles all skill damage modifiers and any procs.
*/
mcm.getInstance().playerVersusSquidChecks(event, attacker, x, type);
/*
* Player versus Player checks, these checks make sure players are not in the same party, etc. They also check for any procs from skills and handle damage modifiers.
*/
mcm.getInstance().playerVersusPlayerChecks(x, attacker, event, plugin);
/*
* Player versus Animals checks, these checks handle any skill modifiers or procs
*/
mcm.getInstance().playerVersusAnimalsChecks(x, attacker, event, type);
}
}
public boolean isBow(ItemStack is){
if (is.getTypeId() == 261){
return true;
} else {
return false;
}
}
public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
Entity y = event.getDamager();
Entity x = event.getEntity();
/*
* Defender is player
*/
if(y instanceof Player){
Player attacker = (Player)y;
if(mcPermissions.getInstance().archery(attacker)){
/*
* Defender is Monster
*/
if(x instanceof Monster){
Monster defender = (Monster)x;
if(mcUsers.getProfile(attacker).getArcheryInt() >= 50 && mcUsers.getProfile(attacker).getArcheryInt() < 250)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 1));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 250 && mcUsers.getProfile(attacker).getArcheryInt() < 575)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 2));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 575 && mcUsers.getProfile(attacker).getArcheryInt() < 725)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 3));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 725 && mcUsers.getProfile(attacker).getArcheryInt() < 1000)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 4));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 1000)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 5));
if(defender.getHealth() <= 0)
mcm.getInstance().simulateNaturalDrops(defender);
//XP
if(Math.random() * 10 > 7){
mcUsers.getProfile(attacker).skillUpArchery(1);
attacker.sendMessage(ChatColor.YELLOW+"Archery skill increased by 1. Total ("+mcUsers.getProfile(attacker).getArchery()+")");
}
}
/*
* Defender is Animals
*/
if(x instanceof Animals){
Animals defender = (Animals)x;
if(mcUsers.getProfile(attacker).getArcheryInt() >= 50 && mcUsers.getProfile(attacker).getArcheryInt() < 250)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 1));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 250 && mcUsers.getProfile(attacker).getArcheryInt() < 575)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 2));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 575 && mcUsers.getProfile(attacker).getArcheryInt() < 725)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 3));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 725 && mcUsers.getProfile(attacker).getArcheryInt() < 1000)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 4));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 1000)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 5));
if(defender.getHealth() <= 0)
mcm.getInstance().simulateNaturalDrops(defender);
}
/*
* Defender is Squid
*/
if(x instanceof Squid){
Squid defender = (Squid)x;
if(mcUsers.getProfile(attacker).getArcheryInt() >= 50 && mcUsers.getProfile(attacker).getArcheryInt() < 250)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 1));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 250 && mcUsers.getProfile(attacker).getArcheryInt() < 575)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 2));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 575 && mcUsers.getProfile(attacker).getArcheryInt() < 725)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 3));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 725 && mcUsers.getProfile(attacker).getArcheryInt() < 1000)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 4));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 1000)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 5));
if(defender.getHealth() <= 0)
mcm.getInstance().simulateNaturalDrops(defender);
}
/*
* Attacker is Player
*/
if(x instanceof Player){
Player defender = (Player)x;
/*
* Stuff for the daze proc
*/
if(mcUsers.getProfile(attacker).inParty() && mcUsers.getProfile(defender).inParty()){
if(mcm.getInstance().inSameParty(defender, attacker)){
event.setCancelled(true);
return;
}
}
Location loc = defender.getLocation();
if(Math.random() * 10 > 5){
loc.setPitch(90);
} else {
loc.setPitch(-90);
}
/*
* Check the proc
*/
if(mcUsers.getProfile(attacker).getArcheryInt() >= 300 && mcUsers.getProfile(attacker).getArcheryInt() < 400){
if(Math.random() * 10 > 7){
defender.teleportTo(loc);
defender.sendMessage(ChatColor.DARK_RED+"Touched Fuzzy. Felt Dizzy.");
attacker.sendMessage("Target was "+ChatColor.DARK_RED+"Dazed");
}
}
if(mcUsers.getProfile(attacker).getArcheryInt() >= 600){
if(Math.random() * 10 > 4){
defender.teleportTo(loc);
defender.sendMessage(ChatColor.DARK_RED+"Touched Fuzzy. Felt Dizzy.");
attacker.sendMessage("Target was "+ChatColor.DARK_RED+"Dazed");
}
}
if(mcUsers.getProfile(attacker).getArcheryInt() >= 50 && mcUsers.getProfile(attacker).getArcheryInt() < 250)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 1));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 250 && mcUsers.getProfile(attacker).getArcheryInt() < 575)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 2));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 575 && mcUsers.getProfile(attacker).getArcheryInt() < 725)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 3));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 725 && mcUsers.getProfile(attacker).getArcheryInt() < 1000)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 4));
if(mcUsers.getProfile(attacker).getArcheryInt() >= 1000)
defender.setHealth(mcm.getInstance().calculateDamage(defender, 5));
if(defender.getHealth() >= 0){
if(mcUsers.getProfile(defender).isDead())
return;
if(defender.getHealth() <= 0){
mcUsers.getProfile(defender).setDead(true);
for(Player derp : plugin.getServer().getOnlinePlayers()){
derp.sendMessage(ChatColor.GRAY+attacker.getName() + " has " +ChatColor.DARK_RED+"slain "+ChatColor.GRAY+defender.getName() + " with an arrow.");
}
}
}
if(mcUsers.getProfile(defender).isDead())
return;
if(defender.getHealth() - event.getDamage() <= 0){
for(Player derp : plugin.getServer().getOnlinePlayers()){
derp.sendMessage(ChatColor.GRAY+attacker.getName() + " has " +ChatColor.DARK_RED+"slain "+ChatColor.GRAY+defender.getName() + " with the bow and arrow.");
mcUsers.getProfile(defender).setDead(true);
}
}
}
}
}
}
public void onEntityDamage(EntityDamageEvent event) {
Entity x = event.getEntity();
if(x instanceof Player){
Player player = (Player)x;
DamageCause type = event.getCause();
Location loc = player.getLocation();
int xx = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
if(type == DamageCause.FALL){
if(mcUsers.getProfile(player).getAcrobaticsInt() >= 50
&& mcUsers.getProfile(player).getAcrobaticsInt() < 250
&& mcPermissions.getInstance().acrobatics(player)){
if(Math.random() * 10 > 8){
event.setCancelled(true);
player.sendMessage("**ROLLED**");
return;
}
}
if(mcUsers.getProfile(player).getAcrobaticsInt() >= 250
&& mcUsers.getProfile(player).getAcrobaticsInt() < 450
&& mcPermissions.getInstance().acrobatics(player)){
if(Math.random() * 10 > 6){
event.setCancelled(true);
player.sendMessage("**ROLLED**");
return;
}
}
if(mcUsers.getProfile(player).getAcrobaticsInt() >= 450
&& mcUsers.getProfile(player).getAcrobaticsInt() < 750
&& mcPermissions.getInstance().acrobatics(player)){
if(Math.random() * 10 > 4){
event.setCancelled(true);
player.sendMessage("**ROLLED**");
return;
}
}
if(mcUsers.getProfile(player).getAcrobaticsInt() >= 750
&& mcUsers.getProfile(player).getAcrobaticsInt() < 950
&& mcPermissions.getInstance().acrobatics(player)){
if(Math.random() * 10 > 2){
event.setCancelled(true);
player.sendMessage("**BARREL ROLLED**");
return;
}
}
if(mcUsers.getProfile(player).getAcrobaticsInt() >= 950
&& mcPermissions.getInstance().acrobatics(player)){
event.setCancelled(true);
player.sendMessage("**ROLLED... LIKE A BOSS**");
return;
}
if(player.getHealth() - event.getDamage() <= 0)
return;
if(!mcConfig.getInstance().isBlockWatched(loc.getWorld().getBlockAt(xx, y, z))
&& mcPermissions.getInstance().acrobatics(player)){
if(event.getDamage() >= 2 && event.getDamage() < 6){
mcUsers.getProfile(player).skillUpAcrobatics(1);
player.sendMessage(ChatColor.YELLOW+"Acrobatics skill increased by 1. Total ("+mcUsers.getProfile(player).getAcrobatics()+")");
}
if(event.getDamage() >= 6 && event.getDamage() < 19){
mcUsers.getProfile(player).skillUpAcrobatics(2);
player.sendMessage(ChatColor.YELLOW+"Acrobatics skill increased by 2. Total ("+mcUsers.getProfile(player).getAcrobatics()+")");
}
if(event.getDamage() >= 19){
mcUsers.getProfile(player).skillUpAcrobatics(3);
player.sendMessage(ChatColor.YELLOW+"Acrobatics skill increased by 3. Total ("+mcUsers.getProfile(player).getAcrobatics()+")");
}
}
mcConfig.getInstance().addBlockWatch(loc.getWorld().getBlockAt(xx, y, z));
if(player.getHealth() - event.getDamage() <= 0){
if(mcUsers.getProfile(player).isDead())
return;
mcUsers.getProfile(player).setDead(true);
for(Player bidoof : plugin.getServer().getOnlinePlayers()){
bidoof.sendMessage(ChatColor.GRAY+player.getName()+" has "+ChatColor.DARK_RED+"fallen "+ChatColor.GRAY+"to death.");
}
}
}
if(type == DamageCause.DROWNING){
if(mcUsers.getProfile(player).isDead())
return;
if(player.getHealth() - event.getDamage() <= 0){
mcUsers.getProfile(player).setDead(true);
for(Player slipslap : plugin.getServer().getOnlinePlayers()){
slipslap.sendMessage(ChatColor.GRAY+player.getName()+" has "+ChatColor.AQUA+"drowned.");
}
}
}
/*
if(type == DamageCause.FIRE || type == DamageCause.FIRE_TICK){
if(mcUsers.getProfile(player).isDead())
return;
if(player.getHealth() - event.getDamage() <= 0){
mcUsers.getProfile(player).setDead(true);
for(Player slipslap : plugin.getServer().getOnlinePlayers()){
slipslap.sendMessage(ChatColor.GRAY+player.getName()+" has "+ChatColor.RED+"burned "+ChatColor.GRAY+"to death.");
}
}
}
*/
if(type == DamageCause.LAVA){
if(mcUsers.getProfile(player).isDead())
return;
if(player.getHealth() - event.getDamage() <= 0){
mcUsers.getProfile(player).setDead(true);
for(Player slipslap : plugin.getServer().getOnlinePlayers()){
slipslap.sendMessage(ChatColor.GRAY+player.getName()+" has "+ChatColor.RED+"melted "+ChatColor.GRAY+".");
}
}
}
}
}
public void onEntityDeath(EntityDeathEvent event) {
Entity x = event.getEntity();
if(x instanceof Player){
Player player = (Player)x;
if(mcUsers.getProfile(player).isDead()){
mcUsers.getProfile(player).setDead(false);
return;
}
for(Player derp : plugin.getServer().getOnlinePlayers()){
derp.sendMessage(ChatColor.GRAY+player.getName()+" has died.");
}
}
}
public boolean isPlayer(Entity entity){
if (entity instanceof Player) {
return true;
} else{
return false;
}
}
}

View File

@ -0,0 +1,79 @@
package com.gmail.nossr50;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.nijiko.Messaging;
import com.nijiko.permissions.PermissionHandler;
import com.nijiko.permissions.Control;
import com.nijikokun.bukkit.Permissions.Permissions;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.event.player.*;
import org.bukkit.Server;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.entity.Player;
public class mcMMO extends JavaPlugin {
public static final Logger log = Logger.getLogger("Minecraft");
private final mcPlayerListener playerListener = new mcPlayerListener(this);
private final mcBlockListener blockListener = new mcBlockListener(this);
private final mcEntityListener entityListener = new mcEntityListener(this);
private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
private final String name = "mcMMO";
public static PermissionHandler PermissionsHandler = null;
private Permissions permissions;
public mcMMO(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
super(pluginLoader, instance, desc, folder, plugin, cLoader);
}
public void onEnable() {
mcUsers.getInstance().loadUsers();
PluginManager pm = getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Monitor, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_ENTITY, entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_FLOW, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_ITEM, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_ITEM_HELD, playerListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_PROJECTILE, entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_BLOCK, entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.Normal, this);
//Displays a message when plugin is loaded
PluginDescriptionFile pdfFile = this.getDescription();
mcPermissions.initialize(getServer());
System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
}
public void setupPermissions() {
Plugin test = this.getServer().getPluginManager().getPlugin("Permissions");
if(this.PermissionsHandler == null) {
if(test != null) {
this.PermissionsHandler = ((Permissions)test).getHandler();
} else {
log.info(Messaging.bracketize(name) + " Permission system not enabled. Disabling plugin.");
this.getServer().getPluginManager().disablePlugin(this);
}
}
}
public Permissions getPermissions() {
return permissions;
}
public void onDisable() {
System.out.println("mcMMO disabled.");
}
}

View File

@ -0,0 +1,164 @@
package com.gmail.nossr50;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import com.nijikokun.bukkit.Permissions.Permissions;
public class mcPermissions {
//Thanks to myWarp source code for helping me figure this shit out!
private static Permissions permissionsPlugin;
private static boolean permissionsEnabled = false;
private static volatile mcPermissions instance;
public static void initialize(Server server) {
Plugin test = server.getPluginManager().getPlugin("Permissions");
if (test != null) {
Logger log = Logger.getLogger("Minecraft");
permissionsPlugin = ((Permissions) test);
permissionsEnabled = true;
log.log(Level.INFO, "[mcMMO] Permissions enabled.");
} else {
Logger log = Logger.getLogger("Minecraft");
log.log(Level.SEVERE, "[mcMMO] Permissions isn't loaded, there are no restrictions.");
}
}
private boolean permission(Player player, String string) {
return permissionsPlugin.Security.permission(player, string);
}
public boolean mmoedit(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.tools.mmoedit");
} else {
return true;
}
}
public boolean motd(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.motd");
} else {
return true;
}
}
public boolean mySpawn(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.commands.myspawn");
} else {
return true;
}
}
public boolean setMySpawn(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.commands.setmyspawn");
} else {
return true;
}
}
public boolean partyChat(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.chat.partychat");
} else {
return true;
}
}
public boolean partyTeleport(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.commands.ptp");
} else {
return true;
}
}
public boolean whois(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.commands.whois");
} else {
return true;
}
}
public boolean party(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.commands.party");
} else {
return true;
}
}
public boolean adminChat(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.chat.adminchat");
} else {
return true;
}
}
public static mcPermissions getInstance() {
if (instance == null) {
instance = new mcPermissions();
}
return instance;
}
public boolean mining(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.skills.mining");
} else {
return true;
}
}
public boolean woodcutting(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.skills.woodcutting");
} else {
return true;
}
}
public boolean repair(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.skills.repair");
} else {
return true;
}
}
public boolean unarmed(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.skills.unarmed");
} else {
return true;
}
}
public boolean archery(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.skills.archery");
} else {
return true;
}
}
public boolean herbalism(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.skills.herbalism");
} else {
return true;
}
}
public boolean excavation(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.skills.excavation");
} else {
return true;
}
}
public boolean swords(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.skills.swords");
} else {
return true;
}
}
public boolean acrobatics(Player player) {
if (permissionsEnabled) {
return permission(player, "mcmmo.skills.acrobatics");
} else {
return true;
}
}
}

View File

@ -0,0 +1,377 @@
package com.gmail.nossr50;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerItemEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import com.nijikokun.bukkit.Permissions.Permissions;
public class mcPlayerListener extends PlayerListener {
protected static final Logger log = Logger.getLogger("Minecraft");
public Location spawn = null;
private mcMMO plugin;
public mcPlayerListener(mcMMO instance) {
plugin = instance;
}
public void onPlayerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
if(mcPermissions.getInstance().mySpawn(player)){
if(mcUsers.getProfile(player).getMySpawn(player) != null)
event.setRespawnLocation(mcUsers.getProfile(player).getMySpawn(player));
}
}
public Player[] getPlayersOnline() {
return plugin.getServer().getOnlinePlayers();
}
public boolean isPlayer(String playerName){
for(Player herp : getPlayersOnline()){
if(herp.getName().toLowerCase().equals(playerName.toLowerCase())){
return true;
}
}
return false;
}
public Player getPlayer(String playerName){
for(Player herp : getPlayersOnline()){
if(herp.getName().toLowerCase().equals(playerName.toLowerCase())){
return herp;
}
}
return null;
}
public int partyCount(Player player){
int x = 0;
for(Player hurrdurr: getPlayersOnline()){
if(mcUsers.getProfile(player).getParty().equals(mcUsers.getProfile(hurrdurr).getParty()))
x++;
}
return x;
}
public void informPartyMembers(Player player){
int x = 0;
for(Player p : getPlayersOnline()){
if(mcm.getInstance().inSameParty(player, p) && !p.getName().equals(player.getName())){
p.sendMessage(player.getName() + ChatColor.GREEN + " has joined your party");
x++;
}
}
}
public void informPartyMembersQuit(Player player){
int x = 0;
for(Player p : getPlayersOnline()){
if(mcm.getInstance().inSameParty(player, p) && !p.getName().equals(player.getName())){
p.sendMessage(player.getName() + ChatColor.GREEN + " has left your party");
x++;
}
}
}
public void onPlayerJoin(PlayerEvent event) {
Player player = event.getPlayer();
mcUsers.addUser(player);
if(mcPermissions.getInstance().motd(player)){
player.sendMessage(ChatColor.BLUE + "This server is running mcMMO "+plugin.getDescription().getVersion()+" type "+ChatColor.YELLOW+"/mcmmo "+ChatColor.BLUE+ "for help.");
}
}
//Check if string is a player
public void onPlayerItem(PlayerItemEvent event) {
Block block = event.getBlockClicked();
Player player = event.getPlayer();
ItemStack is = player.getItemInHand();
if(mcPermissions.getInstance().herbalism(player)){
//BREADCHECK, CHECKS HERBALISM SKILL FOR BREAD HP MODIFIERS
mcm.getInstance().breadCheck(player, is);
//STEW, CHECKS HERBALISM SKILL FOR BREAD HP MODIFIERS
mcm.getInstance().stewCheck(player, is);
}
if(mcPermissions.getInstance().repair(player)){
//REPAIRCHECK, CHECKS TO MAKE SURE PLAYER IS RIGHT CLICKING AN ANVIL, PLAYER HAS ENOUGH RESOURCES, AND THE ITEM IS NOT AT FULL DURABILITY.
mcm.getInstance().repairCheck(player, is, block);
}
}
public void onPlayerCommand(PlayerChatEvent event) {
Player player = event.getPlayer();
String[] split = event.getMessage().split(" ");
String playerName = player.getName();
//Check if the command is an mcMMO related help command
mcm.getInstance().mcmmoHelpCheck(split, player, event);
if(mcPermissions.getInstance().mmoedit(player) && split[0].equalsIgnoreCase("/mmoedit")){
if(split.length < 3){
player.sendMessage(ChatColor.RED+"Usage is /mmoedit playername skillname newvalue");
return;
}
if(split.length == 4){
if(isPlayer(split[1]) && mcm.getInstance().isInt(split[3]) && mcm.getInstance().isSkill(split[2])){
int newvalue = Integer.valueOf(split[3]);
mcUsers.getProfile(getPlayer(split[1])).modifyskill(newvalue, split[2]);
player.sendMessage(ChatColor.RED+split[2]+" has been modified.");
}
}
else if(split.length == 3){
if(mcm.getInstance().isInt(split[2]) && mcm.getInstance().isSkill(split[1])){
int newvalue = Integer.valueOf(split[2]);
mcUsers.getProfile(player).modifyskill(newvalue, split[1]);
player.sendMessage(ChatColor.RED+split[1]+" has been modified.");
}
} else {
player.sendMessage(ChatColor.RED+"Usage is /mmoedit playername skillname newvalue");
}
}
if(mcUsers.getProfile(player).inParty() && split[0].equalsIgnoreCase("/ptp")){
event.setCancelled(true);
if(!mcPermissions.getInstance().partyTeleport(player)){
player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions.");
return;
}
if(split.length < 2){
player.sendMessage(ChatColor.RED+"Usage is /ptp <playername>");
return;
}
if(isPlayer(split[1])){
Player target = getPlayer(split[1]);
if(mcUsers.getProfile(player).getParty().equals(mcUsers.getProfile(target).getParty())){
player.teleportTo(target);
player.sendMessage(ChatColor.GREEN+"You have teleported to "+target.getName());
target.sendMessage(ChatColor.GREEN+player.getName() + " has teleported to you.");
}
}
}
if((player.isOp() || mcPermissions.getInstance().whois(player)) && split[0].equalsIgnoreCase("/whois")){
event.setCancelled(true);
if(split.length < 2){
player.sendMessage(ChatColor.RED + "Proper usage is /whois <playername>");
return;
}
//if split[1] is a player
if(isPlayer(split[1])){
Player target = getPlayer(split[1]);
double x,y,z;
x = target.getLocation().getX();
y = target.getLocation().getY();
z = target.getLocation().getZ();
player.sendMessage(ChatColor.GREEN + "~~WHOIS RESULTS~~");
player.sendMessage(target.getName());
if(mcUsers.getProfile(target).inParty())
player.sendMessage("Party: "+mcUsers.getProfile(target).getParty());
player.sendMessage("Health: "+target.getHealth()+ChatColor.GRAY+" (20 is full health)");
player.sendMessage("OP: " + target.isOp());
player.sendMessage(ChatColor.GREEN+"~~mcMMO stats~~");
player.sendMessage("Mining Skill: "+mcUsers.getProfile(target).getMining());
player.sendMessage("Repair Skill: "+mcUsers.getProfile(target).getRepair());
player.sendMessage("Woodcutting Skill: "+mcUsers.getProfile(target).getWoodCutting());
player.sendMessage("Unarmed Skill: "+mcUsers.getProfile(target).getUnarmed());
player.sendMessage("Herbalism Skill: "+mcUsers.getProfile(target).getHerbalism());
player.sendMessage("Excavation Skill: "+mcUsers.getProfile(target).getExcavation());
player.sendMessage("Archery Skill: "+mcUsers.getProfile(target).getArchery());
player.sendMessage("Swords Skill: "+mcUsers.getProfile(target).getSwords());
//player.sendMessage("Axes Skill: "+mcUsers.getProfile(target).getAxes());
player.sendMessage("Acrobatics Skill: "+mcUsers.getProfile(target).getAcrobatics());
player.sendMessage(ChatColor.GREEN+"~~COORDINATES~~");
player.sendMessage("X: "+x);
player.sendMessage("Y: "+y);
player.sendMessage("Z: "+z);
}
}
if(split[0].equalsIgnoreCase("/setmyspawn")){
if(!mcPermissions.getInstance().setMySpawn(player)){
player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions.");
return;
}
event.setCancelled(true);
double x = player.getLocation().getX();
double y = player.getLocation().getY();
double z = player.getLocation().getZ();
mcUsers.getProfile(player).setMySpawn(x, y, z);
player.sendMessage(ChatColor.DARK_AQUA + "Myspawn has been set to your current location.");
}
if(split[0].equalsIgnoreCase("/stats")){
event.setCancelled(true);
player.sendMessage(ChatColor.DARK_RED + "mcMMO stats");
player.sendMessage(ChatColor.YELLOW + "Mining Skill: " + ChatColor.GREEN + mcUsers.getProfile(player).getMining());
player.sendMessage(ChatColor.YELLOW + "Repair Skill: "+ ChatColor.GREEN + mcUsers.getProfile(player).getRepair());
player.sendMessage(ChatColor.YELLOW + "Woodcutting Skill: "+ ChatColor.GREEN + mcUsers.getProfile(player).getWoodCutting());
player.sendMessage(ChatColor.YELLOW + "Unarmed Skill: "+ ChatColor.GREEN + mcUsers.getProfile(player).getUnarmed());
player.sendMessage(ChatColor.YELLOW + "Herbalism Skill: "+ ChatColor.GREEN + mcUsers.getProfile(player).getHerbalism());
player.sendMessage(ChatColor.YELLOW + "Excavation Skill: "+ ChatColor.GREEN + mcUsers.getProfile(player).getExcavation());
player.sendMessage(ChatColor.YELLOW + "Archery Skill: "+ ChatColor.GREEN + mcUsers.getProfile(player).getArchery());
player.sendMessage(ChatColor.YELLOW + "Swords Skill: " + ChatColor.GREEN + mcUsers.getProfile(player).getSwords());
//player.sendMessage(ChatColor.YELLOW+ "Axes Skill: " + ChatColor.GREEN + mcUsers.getProfile(player).getAxes());
player.sendMessage(ChatColor.YELLOW + "Acrobatics Skill: " + ChatColor.GREEN + mcUsers.getProfile(player).getAcrobatics());
player.sendMessage(ChatColor.DARK_RED+"TOTAL SKILL: "+ChatColor.GREEN+
(mcUsers.getProfile(player).getAcrobaticsInt()+
mcUsers.getProfile(player).getArcheryInt()+
mcUsers.getProfile(player).getAxesInt()+
mcUsers.getProfile(player).getExcavationInt()+
mcUsers.getProfile(player).getHerbalismInt()+
mcUsers.getProfile(player).getMiningInt()+
mcUsers.getProfile(player).getRepairInt()+
mcUsers.getProfile(player).getSwordsInt()+
mcUsers.getProfile(player).getUnarmedInt()+
mcUsers.getProfile(player).getWoodCuttingint())
);
}
//Invite Command
if(mcPermissions.getInstance().party(player) && split[0].equalsIgnoreCase("/invite")){
if(!mcUsers.getProfile(player).inParty()){
player.sendMessage(ChatColor.RED+"You are not in a party.");
return;
}
if(split.length < 2){
player.sendMessage(ChatColor.RED+"Usage is /invite <playername");
return;
}
if(mcUsers.getProfile(player).inParty() && split.length >= 2 && isPlayer(split[1])){
Player target = getPlayer(split[1]);
mcUsers.getProfile(target).modifyInvite(mcUsers.getProfile(player).getParty());
player.sendMessage(ChatColor.GREEN+"Invite sent successfully");
target.sendMessage(ChatColor.RED+"ALERT: "+ChatColor.GREEN+"You have received a party invite for "+mcUsers.getProfile(target).getInvite());
target.sendMessage(ChatColor.YELLOW+"Type "+ChatColor.GREEN+"/accept"+ChatColor.YELLOW+" to accept the invite");
}
}
//Accept invite
if(mcPermissions.getInstance().party(player) && split[0].equalsIgnoreCase("/accept")){
if(mcUsers.getProfile(player).hasPartyInvite()){
if(mcUsers.getProfile(player).inParty()){
informPartyMembersQuit(player);
}
mcUsers.getProfile(player).acceptInvite();
informPartyMembers(player);
player.sendMessage(ChatColor.GREEN+"Invite accepted. You have joined party ("+mcUsers.getProfile(player).getParty()+")");
} else {
player.sendMessage(ChatColor.RED+"You have no invites at this time");
}
}
//Party command
if(split[0].equalsIgnoreCase("/party")){
if(!mcPermissions.getInstance().party(player)){
player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions.");
return;
}
event.setCancelled(true);
if(split.length == 1 && !mcUsers.getProfile(player).inParty()){
player.sendMessage("Proper usage is /party <name> or 'q' to quit");
return;
}
if(split.length == 1 && mcUsers.getProfile(player).inParty()){
String tempList = "";
int x = 0;
for(Player p : plugin.getServer().getOnlinePlayers())
{
if(mcUsers.getProfile(player).getParty().equals(mcUsers.getProfile(p).getParty())){
if(p != null && x+1 >= partyCount(player)){
tempList+= p.getName();
x++;
}
if(p != null && x < partyCount(player)){
tempList+= p.getName() +", ";
x++;
}
}
}
player.sendMessage(ChatColor.GREEN+"You are in party \""+mcUsers.getProfile(player).getParty()+"\"");
player.sendMessage(ChatColor.GREEN + "Party Members ("+ChatColor.WHITE+tempList+ChatColor.GREEN+")");
}
if(split.length > 1 && split[1].equals("q") && mcUsers.getProfile(player).inParty()){
informPartyMembersQuit(player);
mcUsers.getProfile(player).removeParty();
player.sendMessage(ChatColor.RED + "You have left that party");
return;
}
if(split.length >= 2){
mcUsers.getProfile(player).setParty(split[1]);
player.sendMessage("Joined Party: " + split[1]);
informPartyMembers(player);
}
}
if(split[0].equalsIgnoreCase("/p")){
if(!mcPermissions.getInstance().party(player)){
player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions.");
return;
}
event.setCancelled(true);
if(mcConfig.getInstance().isAdminToggled(player.getName()))
mcConfig.getInstance().toggleAdminChat(playerName);
mcConfig.getInstance().togglePartyChat(playerName);
if(mcConfig.getInstance().isPartyToggled(playerName)){
player.sendMessage(ChatColor.GREEN + "Party Chat Toggled On");
} else {
player.sendMessage(ChatColor.GREEN + "Party Chat Toggled " + ChatColor.RED + "Off");
}
}
if(split[0].equalsIgnoreCase("/a") && (player.isOp() || mcPermissions.getInstance().adminChat(player))){
if(!mcPermissions.getInstance().adminChat(player) && !player.isOp()){
player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions.");
return;
}
event.setCancelled(true);
if(mcConfig.getInstance().isPartyToggled(player.getName()))
mcConfig.getInstance().togglePartyChat(playerName);
mcConfig.getInstance().toggleAdminChat(playerName);
if(mcConfig.getInstance().isAdminToggled(playerName)){
player.sendMessage(ChatColor.AQUA + "Admin chat toggled " + ChatColor.GREEN + "On");
} else {
player.sendMessage(ChatColor.AQUA + "Admin chat toggled " + ChatColor.RED + "Off");
}
}
if(split[0].equalsIgnoreCase("/myspawn")){
if(!mcPermissions.getInstance().mySpawn(player)){
player.sendMessage(ChatColor.YELLOW+"[mcMMO]"+ChatColor.DARK_RED +" Insufficient permissions.");
return;
}
event.setCancelled(true);
if(mcUsers.getProfile(player).getMySpawn(player) != null){
player.getInventory().clear();
player.setHealth(20);
player.teleportTo(mcUsers.getProfile(player).getMySpawn(player));
player.sendMessage("Inventory cleared & health restored");
}else{
player.sendMessage(ChatColor.RED+"Configure your myspawn first with /setmyspawn");
}
}
}
public void onItemHeldChange(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
}
public void onPlayerChat(PlayerChatEvent event) {
Player player = event.getPlayer();
String[] split = event.getMessage().split(" ");
String x = ChatColor.GREEN + "(" + ChatColor.WHITE + player.getName() + ChatColor.GREEN + ") ";
String y = ChatColor.AQUA + "{" + ChatColor.WHITE + player.getName() + ChatColor.AQUA + "} ";
if(mcConfig.getInstance().isPartyToggled(player.getName())){
event.setCancelled(true);
log.log(Level.INFO, "[P]("+mcUsers.getProfile(player).getParty()+")"+"<"+player.getName()+"> "+event.getMessage());
for(Player herp : plugin.getServer().getOnlinePlayers()){
if(mcUsers.getProfile(herp).inParty()){
if(mcm.getInstance().inSameParty(herp, player)){
herp.sendMessage(x+event.getMessage());
}
}
}
return;
}
if((player.isOp() || mcPermissions.getInstance().adminChat(player))
&& mcConfig.getInstance().isAdminToggled(player.getName())){
log.log(Level.INFO, "[A]"+"<"+player.getName()+"> "+event.getMessage());
event.setCancelled(true);
for(Player herp : plugin.getServer().getOnlinePlayers()){
if(herp.isOp()){
herp.sendMessage(y+event.getMessage());
}
}
return;
}
}
}

View File

@ -0,0 +1,840 @@
package com.gmail.nossr50;
import java.io.*;
import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.entity.*;
public class mcUsers {
private static volatile mcUsers instance;
protected static final Logger log = Logger.getLogger("Minecraft");
String location = "mcmmo.users";
public static PlayerList players = new PlayerList();
private Properties properties = new Properties();
//To load
public void load() throws IOException {
properties.load(new FileInputStream(location));
}
//To save
public void save() {
try {
properties.store(new FileOutputStream(location), null);
}catch(IOException ex) {
}
}
public void loadUsers(){
File theDir = new File(location);
if(!theDir.exists()){
//properties = new PropertiesFile(location);
FileWriter writer = null;
try {
writer = new FileWriter(location);
writer.write("#Storage place for user information\r\n");
} catch (Exception e) {
log.log(Level.SEVERE, "Exception while creating " + location, e);
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
log.log(Level.SEVERE, "Exception while closing writer for " + location, e);
}
}
} else {
//properties = new PropertiesFile(location);
try {
load();
} catch (IOException e) {
log.log(Level.SEVERE, "Exception while loading " + location, e);
}
}
}
//=====================================================================
//Function: addUser
//Input: Player player: The player to create a profile for
//Output: none
//Use: Loads the profile for the specified player
//=====================================================================
public static void addUser(Player player){
players.addPlayer(player);
}
//=====================================================================
//Function: removeUser
//Input: Player player: The player to stop following
//Output: none
//Use: Creates the player profile
//=====================================================================
public static void removeUser(Player player){
players.removePlayer(player);
}
//=====================================================================
//Function: getProfile
//Input: Player player: The player to find the profile for
//Output: PlayerList.PlayerProfile: The profile
//Use: Gets the player profile
//=====================================================================
public static PlayerList.PlayerProfile getProfile(Player player){
return players.findProfile(player);
}
public static mcUsers getInstance() {
if (instance == null) {
instance = new mcUsers();
}
return instance;
}
public static void getRow(){
}
}
class PlayerList
{
protected static final Logger log = Logger.getLogger("Minecraft");
ArrayList<PlayerProfile> players;
//=====================================================================
//Function: PlayerList
//Input: Player player: The player to create a profile object for
//Output: none
//Use: Initializes the ArrayList
//=====================================================================
public PlayerList() { players = new ArrayList<PlayerProfile>(); }
//=====================================================================
//Function: addPlayer
//Input: Player player: The player to add
//Output: None
//Use: Add a profile of the specified player
//=====================================================================
public void addPlayer(Player player)
{
players.add(new PlayerProfile(player));
}
//=====================================================================
//Function: removePlayer
//Input: Player player: The player to remove
//Output: None
//Use: Remove the profile of the specified player
//=====================================================================
public void removePlayer(Player player)
{
players.remove(findProfile(player));
}
//=====================================================================
//Function: findProfile
//Input: Player player: The player to find's profile
//Output: PlayerProfile: The profile of the specified player
//Use: Get the profile for the specified player
//=====================================================================
public PlayerProfile findProfile(Player player)
{
for(PlayerProfile ply : players)
{
if(ply.isPlayer(player))
return ply;
}
return null;
}
class PlayerProfile
{
protected final Logger log = Logger.getLogger("Minecraft");
private String playerName, gather, wgather, woodcutting, repair, mining, party, myspawn, unarmed, herbalism, excavation,
archery, swords, axes, invite, acrobatics;
private boolean dead;
char defaultColor;
String location = "mcmmo.users";
//=====================================================================
//Function: PlayerProfile
//Input: Player player: The player to create a profile object for
//Output: none
//Use: Loads settings for the player or creates them if they don't
// exist.
//=====================================================================
public PlayerProfile(Player player)
{
//Declare things
playerName = player.getName();
party = new String();
myspawn = new String();
mining = new String();
repair = new String();
unarmed = new String();
herbalism = new String();
excavation = new String();
archery = new String();
swords = new String();
axes = new String();
acrobatics = new String();
invite = new String();
//mining = "0";
wgather = new String();
//wgather = "0";
woodcutting = new String();
//woodcutting = "0";
gather = new String();
//gather = "0";
party = null;
dead = false;
//Try to load the player and if they aren't found, append them
if(!load())
addPlayer();
}
public boolean load()
{
try {
//Open the user file
FileReader file = new FileReader(location);
BufferedReader in = new BufferedReader(file);
String line = "";
while((line = in.readLine()) != null)
{
//Find if the line contains the player we want.
String[] character = line.split(":");
if(!character[0].equals(playerName)){continue;}
//Get Mining
if(character.length > 1)
mining = character[1];
//Myspawn
if(character.length > 2)
myspawn = character[2];
//Party
if(character.length > 3)
party = character[3];
//Mining Gather
if(character.length > 4)
gather = character[4];
if(character.length > 5)
woodcutting = character[5];
if(character.length > 6)
wgather = character[6];
if(character.length > 7)
repair = character[7];
if(character.length > 8)
unarmed = character[8];
if(character.length > 9)
herbalism = character[9];
if(character.length > 10)
excavation = character[10];
if(character.length > 11)
archery = character[11];
if(character.length > 12)
swords = character[12];
if(character.length > 13)
axes = character[13];
if(character.length > 14)
acrobatics = character[14];
in.close();
return true;
}
in.close();
} catch (Exception e) {
log.log(Level.SEVERE, "Exception while reading "
+ location + " (Are you sure you formatted it correctly?)", e);
}
return false;
}
//=====================================================================
// Function: save
// Input: none
// Output: None
// Use: Writes current values of PlayerProfile to disk
// Call this function to save current values
//=====================================================================
public void save()
{
try {
//Open the file
FileReader file = new FileReader(location);
BufferedReader in = new BufferedReader(file);
StringBuilder writer = new StringBuilder();
String line = "";
//While not at the end of the file
while((line = in.readLine()) != null)
{
//Read the line in and copy it to the output it's not the player
//we want to edit
if(!line.split(":")[0].equalsIgnoreCase(playerName))
{
writer.append(line).append("\r\n");
//Otherwise write the new player information
} else {
writer.append(playerName + ":");
writer.append(mining + ":");
writer.append(myspawn + ":");
writer.append(party+":");
writer.append(gather+":");
writer.append(woodcutting+":");
writer.append(wgather+":");
writer.append(repair+":");
writer.append(unarmed+":");
writer.append(herbalism+":");
writer.append(excavation+":");
writer.append(archery+":");
writer.append(swords+":");
writer.append(axes+":");
writer.append(acrobatics+":");
writer.append("\r\n");
}
}
in.close();
//Write the new file
FileWriter out = new FileWriter(location);
out.write(writer.toString());
out.close();
} catch (Exception e) {
log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e);
}
}
public void addPlayer()
{
try {
//Open the file to write the player
FileWriter file = new FileWriter(location, true);
BufferedWriter out = new BufferedWriter(file);
//Add the player to the end
out.append(playerName + ":");
out.append(0 + ":"); //mining
out.append(myspawn+":");
out.append(party+":");
out.append(0+":"); //gather
out.append(0+":"); //woodcutting
out.append(0+":"); //wgather
out.append(0+":"); //repair
out.append(0+":"); //unarmed
out.append(0+":"); //herbalism
out.append(0+":"); //excavation
out.append(0+":"); //archery
out.append(0+":"); //swords
out.append(0+":"); //axes
out.append(0+":"); //acrobatics
//Add more in the same format as the line above
out.newLine();
out.close();
} catch (Exception e) {
log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e);
}
}
//=====================================================================
//Function: isPlayer
//Input: None
//Output: Player: The player this profile belongs to
//Use: Finds if this profile belongs to a specified player
//=====================================================================
public boolean isPlayer(Player player)
{
return player.getName().equals(playerName);
}
public void skillUpAxes(int newskill){
int x = 0;
if(axes != null){
if(isInt(axes)){
x = Integer.parseInt(axes);
}else {
axes = "0";
x = Integer.parseInt(axes);
}
}
x += newskill;
axes = Integer.toString(x);
save();
}
public void skillUpAcrobatics(int newskill){
int x = 0;
if(acrobatics != null){
if(isInt(acrobatics)){
x = Integer.parseInt(acrobatics);
}else {
acrobatics = "0";
x = Integer.parseInt(acrobatics);
}
}
x += newskill;
acrobatics = Integer.toString(x);
save();
}
public void skillUpSwords(int newskill){
int x = 0;
if(swords != null){
if(isInt(swords)){
x = Integer.parseInt(swords);
}else {
swords = "0";
x = Integer.parseInt(swords);
}
}
x += newskill;
swords = Integer.toString(x);
save();
}
public void skillUpArchery(int newskill){
int x = 0;
if(archery != null){
if(isInt(archery)){
x = Integer.parseInt(archery);
}else {
archery = "0";
x = Integer.parseInt(archery);
}
}
x += newskill;
archery = Integer.toString(x);
save();
}
public void skillUpRepair(int newskill){
int x = 0;
if(repair != null){
if(isInt(repair)){
x = Integer.parseInt(repair);
}else {
repair = "0";
x = Integer.parseInt(repair);
}
}
x += newskill;
repair = Integer.toString(x);
save();
}
public void skillUpMining(int newmining){
int x = 0;
if(mining != null){
if(isInt(mining)){
x = Integer.parseInt(mining);
}else {
mining = "0";
x = Integer.parseInt(mining);
}
}
x += newmining;
mining = Integer.toString(x);
save();
}
public void skillUpUnarmed(int newskill){
int x = 0;
if(unarmed != null){
if(isInt(unarmed)){
x = Integer.parseInt(unarmed);
}else {
unarmed = "0";
x = Integer.parseInt(unarmed);
}
}
x += newskill;
unarmed = Integer.toString(x);
save();
}
public void skillUpHerbalism(int newskill){
int x = 0;
if(herbalism != null){
if(isInt(herbalism)){
x = Integer.parseInt(herbalism);
}else {
herbalism = "0";
x = Integer.parseInt(herbalism);
}
}
x += newskill;
herbalism = Integer.toString(x);
save();
}
public void skillUpExcavation(int newskill){
int x = 0;
if(excavation != null){
if(isInt(excavation)){
x = Integer.parseInt(excavation);
}else {
excavation = "0";
x = Integer.parseInt(excavation);
}
}
x += newskill;
excavation = Integer.toString(x);
save();
}
public void skillUpWoodcutting(int newskill){
int x = 0;
if(woodcutting != null){
if(isInt(woodcutting)){
x = Integer.parseInt(woodcutting);
}else {
woodcutting = "0";
x = Integer.parseInt(woodcutting);
}
}
x += newskill;
woodcutting = Integer.toString(x);
save();
}
public String getRepair(){
if(repair != null && !repair.equals("") && !repair.equals("null")){
return repair;
} else {
return "0";
}
}
public String getMining(){
if(mining != null && !mining.equals("") && !mining.equals("null")){
return mining;
} else {
return "0";
}
}
public String getUnarmed(){
if(unarmed != null && !unarmed.equals("") && !unarmed.equals("null")){
return unarmed;
} else {
return "0";
}
}
public String getHerbalism(){
if(herbalism != null && !herbalism.equals("") && !herbalism.equals("null")){
return herbalism;
} else {
return "0";
}
}
public String getExcavation(){
if(excavation != null && !excavation.equals("") && !excavation.equals("null")){
return excavation;
} else {
return "0";
}
}
public String getArchery(){
if(archery != null && !archery.equals("") && !archery.equals("null")){
return archery;
} else {
return "0";
}
}
public String getSwords(){
if(swords != null && !swords.equals("") && !swords.equals("null")){
return swords;
} else {
return "0";
}
}
public String getAxes(){
if(axes != null && !axes.equals("") && !axes.equals("null")){
return axes;
} else {
return "0";
}
}
public String getAcrobatics(){
if(acrobatics != null && !acrobatics.equals("") && !acrobatics.equals("null")){
return acrobatics;
} else {
return "0";
}
}
public int getMiningInt(){
if(isInt(mining)){
int x = Integer.parseInt(mining);
return x;
} else{
return 0;
}
}
public int getUnarmedInt(){
if(isInt(unarmed)){
int x = Integer.parseInt(unarmed);
return x;
} else{
return 0;
}
}
public int getArcheryInt(){
if(isInt(archery)){
int x = Integer.parseInt(archery);
return x;
} else{
return 0;
}
}
public int getSwordsInt(){
if(isInt(swords)){
int x = Integer.parseInt(swords);
return x;
} else{
return 0;
}
}
public int getAxesInt(){
if(isInt(axes)){
int x = Integer.parseInt(axes);
return x;
} else{
return 0;
}
}
public int getAcrobaticsInt(){
if(isInt(acrobatics)){
int x = Integer.parseInt(acrobatics);
return x;
} else{
return 0;
}
}
public int getHerbalismInt(){
if(isInt(herbalism)){
int x = Integer.parseInt(herbalism);
return x;
} else{
return 0;
}
}
public int getExcavationInt(){
if(isInt(excavation)){
int x = Integer.parseInt(excavation);
return x;
} else{
return 0;
}
}
public int getRepairInt(){
if(isInt(repair)){
int x = Integer.parseInt(repair);
return x;
} else{
return 0;
}
}
public int getWoodCuttingint(){
if(isInt(woodcutting)){
int x = Integer.parseInt(woodcutting);
return x;
} else{
return 0;
}
}
public String getWoodCutting(){
if(woodcutting != null && !woodcutting.equals("") && !woodcutting.equals("null")){
return woodcutting;
} else {
return "0";
}
}
public void addwgather(int newgather)
{
int x = 0;
if(isInt(wgather)){
x = Integer.parseInt(wgather);
}
x += newgather;
wgather = String.valueOf(x);
save();
}
public void removewgather(int newgather){
int x = 0;
if(isInt(wgather)){
x = Integer.parseInt(wgather);
}
x -= newgather;
wgather = String.valueOf(x);
save();
}
public void addgather(int newgather)
{
int x = 0;
if(isInt(gather)){
x = Integer.parseInt(gather);
} else {
x = 0;
}
x += newgather;
gather = String.valueOf(x);
save();
}
public void removegather(int newgather){
int x = 0;
if(isInt(gather)){
x = Integer.parseInt(gather);
}
x -= newgather;
gather = String.valueOf(x);
save();
}
public boolean isInt(String string){
try {
int x = Integer.parseInt(string);
}
catch(NumberFormatException nFE) {
return false;
}
return true;
}
public boolean isDouble(String string){
try {
Double x = Double.valueOf(string);
}
catch(NumberFormatException nFE) {
return false;
}
return true;
}
public void acceptInvite(){
party = invite;
invite = "";
save();
}
public void modifyInvite(String invitename){
invite = invitename;
}
//Returns player gather
public String getgather() { return gather; }
public String getInvite() { return invite; }
public String getwgather() { return wgather; }
public int getwgatheramt() {
if(isInt(wgather)){
return Integer.parseInt(getwgather());
} else {
wgather = "0";
save();
return 0;
}
}
public void modifyskill(int newvalue, String skillname){
if(skillname.equals("mining")){
mining = String.valueOf(newvalue);
}
if(skillname.equals("woodcutting")){
woodcutting = String.valueOf(newvalue);
}
if(skillname.equals("repair")){
repair = String.valueOf(newvalue);
}
if(skillname.equals("herbalism")){
herbalism = String.valueOf(newvalue);
}
if(skillname.equals("acrobatics")){
acrobatics = String.valueOf(newvalue);
}
if(skillname.equals("swords")){
swords = String.valueOf(newvalue);
}
if(skillname.equals("archery")){
archery = String.valueOf(newvalue);
}
if(skillname.equals("unarmed")){
unarmed = String.valueOf(newvalue);
}
if(skillname.equals("excavation")){
excavation = String.valueOf(newvalue);
}
save();
}
public int getgatheramt() {
if(isInt(gather)){
return Integer.parseInt(getgather());
} else {
gather = "0";
save();
return 0;
}
}
//Store the player's party
public void setParty(String newParty)
{
party = newParty;
save();
}
//Retrieve the player's party
public String getParty() {return party;}
//Remove party
public void removeParty() {
party = null;
save();
}
//Retrieve whether or not the player is in a party
public boolean inParty() {
if(party != null && !party.equals("") && !party.equals("null")){
return true;
} else {
return false;
}
}
//Retrieve whether or not the player has an invite
public boolean hasPartyInvite() {
if(invite != null && !invite.equals("") && !invite.equals("null")){
return true;
} else {
return false;
}
}
//Save a users spawn location
public void setMySpawn(double x, double y, double z){
myspawn = x+","+y+","+z;
save();
}
public String getX(){
String[] split = myspawn.split(",");
String x = split[0];
return x;
}
public String getY(){
String[] split = myspawn.split(",");
String y = split[1];
return y;
}
public String getZ(){
String[] split = myspawn.split(",");
String z = split[2];
return z;
}
public void setDead(boolean x){
dead = x;
save();
}
public boolean isDead(){
return dead;
}
public Location getMySpawn(Player player){
Location loc = player.getLocation();
if(isDouble(getX()) && isDouble(getY()) && isDouble(getX())){
loc.setX(Double.parseDouble(mcUsers.getProfile(player).getX()));
loc.setY(Double.parseDouble(mcUsers.getProfile(player).getY()));
loc.setZ(Double.parseDouble(mcUsers.getProfile(player).getZ()));
} else {
return null;
}
loc.setYaw(0);
loc.setPitch(0);
return loc;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,3 @@
name: mcMMO name: mcMMO
main: com.bukkit.nossr50.mcMMO.mcMMO main: com.gmail.nossr50.mcMMO
version: 0.5.15 version: 0.5.17