mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Fixed more stuff, added in Repair skill.
This commit is contained in:
parent
7627b7f7e4
commit
6e5c93f955
@ -21,6 +21,8 @@ public class mcBlockListener extends BlockListener {
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
Block block = event.getBlock();
|
||||
mcConfig.getInstance().addBlockWatch(block);
|
||||
if(block.getTypeId() == 42)
|
||||
event.getPlayer().sendMessage(ChatColor.DARK_RED+"You have placed an anvil, anvils can repair tools and armor.");
|
||||
}
|
||||
public void blockProcSimulate(Block block){
|
||||
Location loc = block.getLocation();
|
||||
|
@ -38,6 +38,7 @@ public class mcMMO extends JavaPlugin {
|
||||
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);
|
||||
//Displays a message when plugin is loaded
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
|
||||
|
@ -2,10 +2,14 @@ package com.bukkit.nossr50.mcMMO;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Item;
|
||||
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.PlayerListener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class mcPlayerListener extends PlayerListener {
|
||||
public Location spawn = null;
|
||||
@ -17,13 +21,7 @@ public class mcPlayerListener extends PlayerListener {
|
||||
public void onPlayerJoin(PlayerEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
mcUsers.addUser(player);
|
||||
player.sendMessage(ChatColor.DARK_RED+"Welcome to /v/ - Minecraft");
|
||||
player.sendMessage(ChatColor.DARK_RED+"Steam Group: vminecraft");
|
||||
player.sendMessage(ChatColor.AQUA + "This server is running mcMMO type /stats for your information");
|
||||
player.sendMessage(ChatColor.GREEN + "Use "+ChatColor.YELLOW+"/party "+ChatColor.GREEN+"to create/join parties");
|
||||
player.sendMessage(ChatColor.GREEN + "Use "+ChatColor.YELLOW+"/p"+ChatColor.GREEN+" to toggle party chat");
|
||||
player.sendMessage(ChatColor.GREEN + "Use "+ChatColor.YELLOW+"/ptp "+ChatColor.GREEN+"to teleport to party members");
|
||||
player.sendMessage("Set your spawn with "+ChatColor.YELLOW+"/setmyspawn"+ChatColor.WHITE+", Travel to it with /myspawn");
|
||||
player.sendMessage(ChatColor.BLUE + "This server is running mcMMO type "+ChatColor.YELLOW+"/mcmmo "+ChatColor.BLUE+ "for help.");
|
||||
player.sendMessage(ChatColor.RED+"WARNING: "+ChatColor.DARK_GRAY+ "Using /myspawn will clear your inventory!");
|
||||
}
|
||||
//Check if string is a player
|
||||
@ -44,6 +42,7 @@ public class mcPlayerListener extends PlayerListener {
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public Player getPlayer(String playerName){
|
||||
for(Player herp : plugin.getServer().getOnlinePlayers()){
|
||||
if(herp.getName().toLowerCase().equals(playerName.toLowerCase())){
|
||||
@ -52,14 +51,211 @@ public class mcPlayerListener extends PlayerListener {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// IS TOOLS FUNCTION
|
||||
public boolean isTools(ItemStack is){
|
||||
if(is.getTypeId() == 256 || is.getTypeId() == 257 || is.getTypeId() == 258 || is.getTypeId() == 267 || //IRON
|
||||
is.getTypeId() == 276 || is.getTypeId() == 277 || is.getTypeId() == 278 || is.getTypeId() == 279) //DIAMOND
|
||||
{
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isIronTools(ItemStack is){
|
||||
if(is.getTypeId() == 256 || is.getTypeId() == 257 || is.getTypeId() == 258 || is.getTypeId() == 267)
|
||||
{
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDiamondTools(ItemStack is){
|
||||
if(is.getTypeId() == 276 || is.getTypeId() == 277 || is.getTypeId() == 278 || is.getTypeId() == 279)
|
||||
{
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void removeIron(Player player){
|
||||
ItemStack[] inventory = player.getInventory().getContents();
|
||||
for(ItemStack x : inventory){
|
||||
if(x.getTypeId() == 265){
|
||||
if(x.getAmount() == 1){
|
||||
x.setTypeId(0);
|
||||
x.setAmount(0);
|
||||
player.getInventory().setContents(inventory);
|
||||
} else{
|
||||
x.setAmount(x.getAmount() - 1);
|
||||
player.getInventory().setContents(inventory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void removeDiamond(Player player){
|
||||
ItemStack[] inventory = player.getInventory().getContents();
|
||||
for(ItemStack x : inventory){
|
||||
if(x.getTypeId() == 264){
|
||||
if(x.getAmount() == 1){
|
||||
x.setTypeId(0);
|
||||
x.setAmount(0);
|
||||
player.getInventory().setContents(inventory);
|
||||
} else{
|
||||
x.setAmount(x.getAmount() - 1);
|
||||
player.getInventory().setContents(inventory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean hasDiamond(Player player){
|
||||
ItemStack[] inventory = player.getInventory().getContents();
|
||||
for(ItemStack x : inventory){
|
||||
if(x.getTypeId() == 264){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean hasIron(Player player){
|
||||
ItemStack[] inventory = player.getInventory().getContents();
|
||||
for(ItemStack x : inventory){
|
||||
if(x.getTypeId() == 265){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//This determines how much we repair
|
||||
public short getRepairAmount(ItemStack is, short durability, Player player){
|
||||
//IRON SHOVEL
|
||||
if(is.getTypeId() == 256){
|
||||
return 0; //full repair
|
||||
}
|
||||
//DIAMOND SHOVEL
|
||||
if(is.getTypeId() == 277){
|
||||
return 0; //full repair
|
||||
}
|
||||
//IRON TOOLS
|
||||
if(is.getTypeId() == 257 || is.getTypeId() == 258 || is.getTypeId() == 267){
|
||||
if(durability < 84){
|
||||
return 0;
|
||||
}else {
|
||||
if(mcUsers.getProfile(player).getRepairInt() > 750){
|
||||
if(Math.random() * 10 > 2){
|
||||
player.sendMessage(ChatColor.GRAY + "That took no effort.");
|
||||
return 0;
|
||||
}
|
||||
} else if (mcUsers.getProfile(player).getRepairInt() > 450){
|
||||
if(Math.random() * 10 > 4){
|
||||
player.sendMessage(ChatColor.GRAY + "That felt really easy.");
|
||||
return 0;
|
||||
}
|
||||
} else if (mcUsers.getProfile(player).getRepairInt() > 150){
|
||||
if(Math.random() * 10 > 6){
|
||||
player.sendMessage(ChatColor.GRAY + "That felt pretty easy.");
|
||||
return 0;
|
||||
}
|
||||
} else if (mcUsers.getProfile(player).getRepairInt() > 50){
|
||||
if(Math.random() * 10 > 8){
|
||||
player.sendMessage(ChatColor.GRAY + "That felt easy.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return (short) (durability-84);
|
||||
}
|
||||
//DIAMOND TOOLS
|
||||
} else if(is.getTypeId() == 276 || is.getTypeId() == 278 || is.getTypeId() == 279){
|
||||
if(durability < 509){
|
||||
return 0;
|
||||
} else {
|
||||
if(mcUsers.getProfile(player).getRepairInt() > 750){
|
||||
if(Math.random() * 10 > 2){
|
||||
player.sendMessage(ChatColor.GRAY + "That took no effort.");
|
||||
return 0;
|
||||
}
|
||||
} else if (mcUsers.getProfile(player).getRepairInt() > 450){
|
||||
if(Math.random() * 10 > 4){
|
||||
player.sendMessage(ChatColor.GRAY + "That was simple.");
|
||||
return 0;
|
||||
}
|
||||
} else if (mcUsers.getProfile(player).getRepairInt() > 150){
|
||||
if(Math.random() * 10 > 6){
|
||||
player.sendMessage(ChatColor.GRAY + "That felt pretty easy.");
|
||||
return 0;
|
||||
}
|
||||
} else if (mcUsers.getProfile(player).getRepairInt() > 50){
|
||||
if(Math.random() * 10 > 8){
|
||||
player.sendMessage(ChatColor.GRAY + "That felt easy.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return (short) (durability-509);
|
||||
}
|
||||
} else {
|
||||
return durability;
|
||||
}
|
||||
}
|
||||
|
||||
public void onPlayerItem(PlayerItemEvent event) {
|
||||
Block block = event.getBlockClicked();
|
||||
Player player = event.getPlayer();
|
||||
ItemStack is = player.getItemInHand();
|
||||
if(block != null && block.getTypeId() == 42){
|
||||
short durability = is.getDurability();
|
||||
if(isTools(is) && player.isOp() && block.getTypeId() == 42){
|
||||
if(isIronTools(is) && hasIron(player)){ //Check if its iron and the player has iron
|
||||
is.setDurability(getRepairAmount(is, durability, player));
|
||||
removeIron(player);
|
||||
mcUsers.getProfile(player).skillUpRepair(1);
|
||||
player.sendMessage(ChatColor.YELLOW+"Repair skill increased by 1. Total ("+mcUsers.getProfile(player).getRepair()+")");
|
||||
} else if (isDiamondTools(is) && hasDiamond(player) && mcUsers.getProfile(player).getRepairInt() > 50){ //Check if its diamond and the player has diamonds
|
||||
is.setDurability(getRepairAmount(is, durability, player));
|
||||
removeDiamond(player);
|
||||
mcUsers.getProfile(player).skillUpRepair(1);
|
||||
player.sendMessage(ChatColor.YELLOW+"Repair skill increased by 1. Total ("+mcUsers.getProfile(player).getRepair()+")");
|
||||
} else if (isDiamondTools(is) && mcUsers.getProfile(player).getRepairInt() < 50){
|
||||
player.sendMessage(ChatColor.DARK_RED +"You're not adept enough to repair Diamond");
|
||||
} else if (isDiamondTools(is) && !hasDiamond(player) || isIronTools(is) && !hasIron(player)){
|
||||
if(!hasDiamond(player))
|
||||
player.sendMessage(ChatColor.DARK_RED+"You need more"+ChatColor.BLUE+ "Diamonds");
|
||||
if(!hasIron(player))
|
||||
player.sendMessage(ChatColor.DARK_RED+"You need more"+ChatColor.GRAY+ "Iron");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void onPlayerCommand(PlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
String[] split = event.getMessage().split(" ");
|
||||
String playerName = player.getName();
|
||||
//mcMMO command
|
||||
if(split[0].equalsIgnoreCase("/give")){
|
||||
player.sendMessage("Disabled Bitches");
|
||||
event.setCancelled(true);
|
||||
if(split[0].equalsIgnoreCase("/mcmmo")){
|
||||
player.sendMessage(ChatColor.GRAY+"mcMMO is an RPG inspired plugin");
|
||||
player.sendMessage(ChatColor.GRAY+"You can gain skills in several professions by");
|
||||
player.sendMessage(ChatColor.GRAY+"doing things related to that profession.");
|
||||
player.sendMessage(ChatColor.GRAY+"Mining for example will increase your mining XP.");
|
||||
player.sendMessage(ChatColor.GRAY+"Wood Cutting will increase Wood Cutting, etc...");
|
||||
player.sendMessage(ChatColor.GRAY+"Repairing is simple in mcMMO");
|
||||
player.sendMessage(ChatColor.GRAY+"Say you want to repair an iron shovel");
|
||||
player.sendMessage(ChatColor.GRAY+"start by making an anvil by combining 9 iron ingots");
|
||||
player.sendMessage(ChatColor.GRAY+"on a workbench. Place the anvil and while holding the shovel");
|
||||
player.sendMessage(ChatColor.GRAY+"right click the anvil interact with it, If you have spare iron ingots");
|
||||
player.sendMessage(ChatColor.GRAY+"in your inventory the item will be repaired.");
|
||||
player.sendMessage(ChatColor.GRAY+"You cannot hurt other party members");
|
||||
player.sendMessage(ChatColor.BLUE+"Set your own spawn with "+ChatColor.RED+"/myspawn");
|
||||
player.sendMessage(ChatColor.GREEN+"Based on your skills you will get "+ChatColor.DARK_RED+"random procs "+ChatColor.GREEN+ "when");
|
||||
player.sendMessage(ChatColor.GREEN+"using your profession, like "+ChatColor.DARK_RED+"double drops "+ChatColor.GREEN+"or "+ChatColor.DARK_RED+"better repairs");
|
||||
player.sendMessage(ChatColor.GREEN+"Find out mcMMO commands with /mcc");
|
||||
}
|
||||
if(split[0].equalsIgnoreCase("/mcc")){
|
||||
player.sendMessage(ChatColor.GRAY+"mcMMO has a party system included");
|
||||
player.sendMessage(ChatColor.GRAY+"Commands are /party <name> - to join a party");
|
||||
player.sendMessage(ChatColor.GRAY+"/ptp <name> - party teleport");
|
||||
player.sendMessage(ChatColor.GRAY+"/p - toggles party chat");
|
||||
}
|
||||
if(mcUsers.getProfile(player).inParty() && split[0].equalsIgnoreCase("/ptp")){
|
||||
if(split.length < 2){
|
||||
@ -95,6 +291,7 @@ public class mcPlayerListener extends PlayerListener {
|
||||
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(ChatColor.GREEN+"~~COORDINATES~~");
|
||||
player.sendMessage("X: "+x);
|
||||
@ -117,6 +314,7 @@ public class mcPlayerListener extends PlayerListener {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.DARK_GREEN + "mcMMO stats");
|
||||
player.sendMessage(ChatColor.DARK_GREEN + "Mining Skill: " + mcUsers.getProfile(player).getMining());
|
||||
player.sendMessage(ChatColor.DARK_GREEN + "Repair Skill: " + mcUsers.getProfile(player).getRepair());
|
||||
player.sendMessage(ChatColor.DARK_GREEN + "Woodcutting Skill: "+mcUsers.getProfile(player).getWoodCutting());
|
||||
player.sendMessage(ChatColor.GRAY + "Increases depending on the material you mine");
|
||||
}
|
||||
@ -146,7 +344,7 @@ public class mcPlayerListener extends PlayerListener {
|
||||
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[1].equals("q") && mcUsers.getProfile(player).inParty()){
|
||||
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");
|
||||
@ -189,16 +387,12 @@ public class mcPlayerListener extends PlayerListener {
|
||||
if(split[0].equalsIgnoreCase("/spawn")){
|
||||
if(spawn != null){
|
||||
player.teleportTo(spawn);
|
||||
player.sendMessage("Welcome to spawn, home of the dumbfucks");
|
||||
player.sendMessage("Welcome to spawn, home of the feeble.");
|
||||
return;
|
||||
}
|
||||
player.sendMessage("Spawn isn't configured. Have an OP set it with /setspawn");
|
||||
}
|
||||
}
|
||||
private String String(double x) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
String[] split = event.getMessage().split(" ");
|
||||
|
@ -154,7 +154,7 @@ class PlayerList
|
||||
class PlayerProfile
|
||||
{
|
||||
protected final Logger log = Logger.getLogger("Minecraft");
|
||||
private String playerName, gather, wgather, woodcutting, mining, party, myspawn;
|
||||
private String playerName, gather, wgather, woodcutting, repair, mining, party, myspawn;
|
||||
private boolean dead;
|
||||
char defaultColor;
|
||||
|
||||
@ -175,6 +175,7 @@ class PlayerList
|
||||
party = new String();
|
||||
myspawn = new String();
|
||||
mining = new String();
|
||||
repair = new String();
|
||||
//mining = "0";
|
||||
wgather = new String();
|
||||
//wgather = "0";
|
||||
@ -219,6 +220,8 @@ class PlayerList
|
||||
woodcutting = character[5];
|
||||
if(character.length > 6)
|
||||
wgather = character[6];
|
||||
if(character.length > 7)
|
||||
repair = character[7];
|
||||
in.close();
|
||||
return true;
|
||||
}
|
||||
@ -264,6 +267,7 @@ class PlayerList
|
||||
writer.append(gather+":");
|
||||
writer.append(woodcutting+":");
|
||||
writer.append(wgather+":");
|
||||
writer.append(repair+":");
|
||||
writer.append("\r\n");
|
||||
}
|
||||
}
|
||||
@ -285,12 +289,13 @@ class PlayerList
|
||||
|
||||
//Add the player to the end
|
||||
out.append(playerName + ":");
|
||||
out.append(0 + ":");
|
||||
out.append(0 + ":"); //mining
|
||||
out.append(myspawn+":");
|
||||
out.append(party+":");
|
||||
out.append(0+":");
|
||||
out.append(0+":");
|
||||
out.append(0+":");
|
||||
out.append(0+":"); //gather
|
||||
out.append(0+":"); //woodcutting
|
||||
out.append(0+":"); //wgather
|
||||
out.append(0+":"); //repair
|
||||
//Add more in the same format as the line above
|
||||
|
||||
out.newLine();
|
||||
@ -310,6 +315,20 @@ class PlayerList
|
||||
{
|
||||
return player.getName().equals(playerName);
|
||||
}
|
||||
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){
|
||||
@ -338,6 +357,9 @@ class PlayerList
|
||||
woodcutting = Integer.toString(x);
|
||||
save();
|
||||
}
|
||||
public String getRepair(){
|
||||
return repair;
|
||||
}
|
||||
public String getMining(){
|
||||
return mining;
|
||||
}
|
||||
@ -349,6 +371,14 @@ class PlayerList
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user