mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 22:56:45 +01:00
Added party itemShare mode: EQUAL
Slightly cleaner way of handling equal item sharing. Reset the item share modifier back to base when a player leaves the party Added a new config file for the itemWeights Removed the debug messages. Added Lapis_Ore to itemweights.yml Drop the item on the ground if the winningPlayer's inventory is full. Unneccesary Added a feature which allows the party leader to toggle item share categories.... That should be the rest. ItemWeights to Item_Weights
This commit is contained in:
parent
18510ba851
commit
cbbe436a69
@ -41,6 +41,9 @@ Version 1.4.00-dev
|
||||
+ Added "Holy Hound" ability to Taming
|
||||
+ Added "Shroom Thumb" ability to Herbalism
|
||||
+ Added child.yml config file to choose parents for child skills
|
||||
+ Added '/party itemshare <NONE | EQUAL | RANDOM>' command to choose party item share mode
|
||||
+ Added '/party itemshare <loot | mining | herbalism | woodcutting> <true | false>' command to control items that are shared
|
||||
+ Added itemweights.yml file to determine which items are more valuable for party itemshare
|
||||
= Fixed Green Thumb on wheat not working properly at rank 4
|
||||
= Fixed Green Thumb and Green Terra consuming twice the amount of seed needed
|
||||
= Fixed Green Terra not also checking Green Thumb permissions
|
||||
|
@ -0,0 +1,34 @@
|
||||
package com.gmail.nossr50.config;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
|
||||
public class ItemWeightsConfig extends ConfigLoader {
|
||||
private static ItemWeightsConfig instance;
|
||||
|
||||
private ItemWeightsConfig() {
|
||||
super("itemweights.yml");
|
||||
}
|
||||
|
||||
public static ItemWeightsConfig getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ItemWeightsConfig();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadKeys() {}
|
||||
|
||||
public int getItemWeight(Material material) {
|
||||
String materialName = StringUtils.getPrettyItemString(material).replace(" ", "_");
|
||||
int itemWeight = config.getInt("Item_Weights.Default");
|
||||
|
||||
if (config.getInt("Item_Weights." + materialName) > 0) {
|
||||
itemWeight = config.getInt("Item_Weights." + materialName);
|
||||
}
|
||||
return itemWeight;
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@ public class McMMOPlayer {
|
||||
private boolean ptpEnabled = true;
|
||||
private boolean ptpConfirmRequired = Config.getInstance().getPTPCommandConfirmRequired();
|
||||
private long ptpTimeout;
|
||||
private int itemShareModifier;
|
||||
private boolean partyChatMode;
|
||||
private boolean adminChatMode;
|
||||
|
||||
@ -242,6 +243,20 @@ public class McMMOPlayer {
|
||||
ptpTimeout = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||
}
|
||||
|
||||
public int getItemShareModifier() {
|
||||
if (itemShareModifier < 10) {
|
||||
setItemShareModifier(10);
|
||||
}
|
||||
return itemShareModifier;
|
||||
}
|
||||
|
||||
public void setItemShareModifier(int modifier) {
|
||||
if (modifier < 10) {
|
||||
modifier = 10;
|
||||
}
|
||||
itemShareModifier = modifier;
|
||||
}
|
||||
|
||||
public boolean getAdminChatMode() {
|
||||
return adminChatMode;
|
||||
}
|
||||
|
@ -14,6 +14,10 @@ public class Party {
|
||||
private boolean locked;
|
||||
private ShareHandler.ShareMode xpShareMode = ShareHandler.ShareMode.NONE;
|
||||
private ShareHandler.ShareMode itemShareMode = ShareHandler.ShareMode.NONE;
|
||||
private boolean shareLootDrops = true;
|
||||
private boolean shareMiningDrops = true;
|
||||
private boolean shareHerbalismDrops = true;
|
||||
private boolean shareWoodcuttingDrops = true;
|
||||
|
||||
public List<OfflinePlayer> getMembers() {
|
||||
return members;
|
||||
@ -47,6 +51,39 @@ public class Party {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public boolean sharingLootDrops() {
|
||||
return shareLootDrops;
|
||||
}
|
||||
|
||||
public boolean sharingMiningDrops() {
|
||||
return shareMiningDrops;
|
||||
}
|
||||
|
||||
public boolean sharingHerbalismDrops() {
|
||||
return shareHerbalismDrops;
|
||||
}
|
||||
|
||||
public boolean sharingWoodcuttingDrops() {
|
||||
return shareWoodcuttingDrops;
|
||||
}
|
||||
|
||||
public List<String> getItemShareCategories() { //TODO Locale the category names!
|
||||
List<String> shareCategories = new ArrayList<String>();
|
||||
if (sharingLootDrops()) {
|
||||
shareCategories.add("Loot");
|
||||
}
|
||||
if (sharingMiningDrops()) {
|
||||
shareCategories.add("Mining");
|
||||
}
|
||||
if (sharingHerbalismDrops()) {
|
||||
shareCategories.add("Herbalism");
|
||||
}
|
||||
if (sharingWoodcuttingDrops()) {
|
||||
shareCategories.add("Woodcutting");
|
||||
}
|
||||
return shareCategories;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
@ -78,4 +115,20 @@ public class Party {
|
||||
public ShareHandler.ShareMode getItemShareMode() {
|
||||
return itemShareMode;
|
||||
}
|
||||
|
||||
public void setSharingLootDrops(boolean enabled) {
|
||||
this.shareLootDrops = enabled;
|
||||
}
|
||||
|
||||
public void setSharingMiningDrops(boolean enabled) {
|
||||
this.shareMiningDrops = enabled;
|
||||
}
|
||||
|
||||
public void setSharingHerbalismDrops(boolean enabled) {
|
||||
this.shareHerbalismDrops = enabled;
|
||||
}
|
||||
|
||||
public void setSharingWoodcuttingDrops(boolean enabled) {
|
||||
this.shareWoodcuttingDrops = enabled;
|
||||
}
|
||||
}
|
||||
|
@ -223,6 +223,7 @@ public final class PartyManager {
|
||||
|
||||
if (mcMMOPlayer != null) {
|
||||
mcMMOPlayer.removeParty();
|
||||
mcMMOPlayer.setItemShareModifier(10);
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,6 +240,7 @@ public final class PartyManager {
|
||||
|
||||
if (mcMMOPlayer != null) {
|
||||
mcMMOPlayer.removeParty();
|
||||
mcMMOPlayer.setItemShareModifier(10);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,10 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.ItemWeightsConfig;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.ItemChecks;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
@ -34,6 +36,9 @@ public final class ShareHandler {
|
||||
|
||||
private ShareHandler() {}
|
||||
|
||||
private static List<Player> nearMembers;
|
||||
private static int partySize;
|
||||
|
||||
/**
|
||||
* Distribute Xp amongst party members.
|
||||
*
|
||||
@ -48,7 +53,7 @@ public final class ShareHandler {
|
||||
switch (party.getXpShareMode()) {
|
||||
case EQUAL:
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
List<Player> nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
|
||||
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
|
||||
|
||||
if (nearMembers.isEmpty()) {
|
||||
return false;
|
||||
@ -86,38 +91,95 @@ public final class ShareHandler {
|
||||
Item item = event.getItem();
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
Party party = mcMMOPlayer.getParty();
|
||||
|
||||
switch (party.getItemShareMode()) {
|
||||
case EQUAL:
|
||||
|
||||
return false;
|
||||
case RANDOM:
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
List<Player> nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
|
||||
|
||||
if (nearMembers.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
int partySize = nearMembers.size() + 1;
|
||||
|
||||
event.setCancelled(true);
|
||||
item.remove();
|
||||
|
||||
Player targetPlayer;
|
||||
Player winningPlayer = null;
|
||||
|
||||
ItemStack newStack = itemStack.clone();
|
||||
newStack.setAmount(1);
|
||||
|
||||
//TODO Improve this, if possible make this faster.
|
||||
if (ItemChecks.isMobDrop(itemStack) && !party.sharingLootDrops()) {
|
||||
return false;
|
||||
}
|
||||
else if (ItemChecks.isMiningDrop(itemStack) && !party.sharingMiningDrops()) {
|
||||
return false;
|
||||
}
|
||||
else if (ItemChecks.isHerbalismDrop(itemStack) && !party.sharingHerbalismDrops()) {
|
||||
return false;
|
||||
}
|
||||
else if (ItemChecks.isWoodcuttingDrop(itemStack) && !party.sharingWoodcuttingDrops()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (party.getItemShareMode()) {
|
||||
case EQUAL:
|
||||
McMMOPlayer mcMMOTarget;
|
||||
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
|
||||
|
||||
if (nearMembers.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
nearMembers.add(player);
|
||||
partySize = nearMembers.size();
|
||||
|
||||
event.setCancelled(true);
|
||||
item.remove();
|
||||
int itemWeight = ItemWeightsConfig.getInstance().getItemWeight(itemStack.getType());
|
||||
|
||||
for (int i = 0; i < itemStack.getAmount(); i++) {
|
||||
int highestRoll = 0;
|
||||
|
||||
for (Player member : nearMembers) {
|
||||
McMMOPlayer mcMMOMember = Users.getPlayer(member);
|
||||
int itemShareModifier = mcMMOMember.getItemShareModifier();
|
||||
int diceRoll = Misc.getRandom().nextInt(itemShareModifier);
|
||||
|
||||
if (diceRoll > highestRoll) {
|
||||
highestRoll = diceRoll;
|
||||
|
||||
if (winningPlayer != null) {
|
||||
McMMOPlayer mcMMOWinning = Users.getPlayer(winningPlayer);
|
||||
mcMMOWinning.setItemShareModifier(mcMMOWinning.getItemShareModifier() + itemWeight);
|
||||
}
|
||||
|
||||
winningPlayer = member;
|
||||
}
|
||||
else {
|
||||
mcMMOMember.setItemShareModifier(itemShareModifier + itemWeight);
|
||||
}
|
||||
}
|
||||
|
||||
mcMMOTarget = Users.getPlayer(winningPlayer);
|
||||
mcMMOTarget.setItemShareModifier(mcMMOTarget.getItemShareModifier() - itemWeight);
|
||||
|
||||
if (winningPlayer.getInventory().addItem(newStack).size() != 0) {
|
||||
winningPlayer.getWorld().dropItemNaturally(winningPlayer.getLocation(), newStack);
|
||||
}
|
||||
winningPlayer.updateInventory();
|
||||
}
|
||||
return true;
|
||||
case RANDOM:
|
||||
nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
|
||||
|
||||
if (nearMembers.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
partySize = nearMembers.size() + 1;
|
||||
|
||||
event.setCancelled(true);
|
||||
item.remove();
|
||||
|
||||
for (int i = 0; i < itemStack.getAmount(); i++) {
|
||||
int randomMember = Misc.getRandom().nextInt(partySize);
|
||||
if (randomMember >= nearMembers.size()) {
|
||||
targetPlayer = player;
|
||||
winningPlayer = player;
|
||||
} else {
|
||||
targetPlayer = nearMembers.get(randomMember);
|
||||
winningPlayer = nearMembers.get(randomMember);
|
||||
}
|
||||
targetPlayer.getInventory().addItem(newStack);
|
||||
targetPlayer.updateInventory();
|
||||
|
||||
if (winningPlayer.getInventory().addItem(newStack).size() != 0) {
|
||||
winningPlayer.getWorld().dropItemNaturally(winningPlayer.getLocation(), newStack);
|
||||
}
|
||||
winningPlayer.updateInventory();
|
||||
}
|
||||
return true;
|
||||
case NONE:
|
||||
@ -126,4 +188,3 @@ public final class ShareHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.Party;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.party.ShareHandler;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class PartyInfoCommand implements CommandExecutor {
|
||||
@ -51,6 +52,7 @@ public class PartyInfoCommand implements CommandExecutor {
|
||||
private void displayShareModeInfo() {
|
||||
boolean xpShareEnabled = Config.getInstance().getExpShareEnabled();
|
||||
boolean itemShareEnabled = Config.getInstance().getItemShareEnabled();
|
||||
boolean itemSharingActive = playerParty.getItemShareMode() != ShareHandler.ShareMode.NONE;
|
||||
|
||||
if (!xpShareEnabled && !itemShareEnabled) {
|
||||
return;
|
||||
@ -73,6 +75,9 @@ public class PartyInfoCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Party.ShareMode") + expShareInfo + separator + itemShareInfo);
|
||||
if (itemSharingActive) {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Party.ItemShareCategories", playerParty.getItemShareCategories()));
|
||||
}
|
||||
}
|
||||
|
||||
private void displayPartyHeader() {
|
||||
|
@ -30,22 +30,50 @@ public class PartyItemShareCommand implements CommandExecutor {
|
||||
if (args[1].equalsIgnoreCase("none") || args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("false")) {
|
||||
handleChangingShareMode(ShareMode.NONE);
|
||||
}
|
||||
// else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")) {
|
||||
// handleChangingShareMode(ShareMode.EQUAL);
|
||||
// }
|
||||
else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")) {
|
||||
handleChangingShareMode(ShareMode.EQUAL);
|
||||
}
|
||||
else if (args[1].equalsIgnoreCase("random")) {
|
||||
handleChangingShareMode(ShareMode.RANDOM);
|
||||
}
|
||||
else {
|
||||
// sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | EQUAL | RANDOM>"));
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | RANDOM>"));
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | EQUAL | RANDOM>"));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
case 3:
|
||||
playerParty = Users.getPlayer((Player) sender).getParty();
|
||||
boolean toggle = false;
|
||||
|
||||
if (args[2].equalsIgnoreCase("true") || args[2].equalsIgnoreCase("on")|| args[2].equalsIgnoreCase("enabled")) {
|
||||
toggle = true;
|
||||
}
|
||||
else if (args[2].equalsIgnoreCase("false") || args[2].equalsIgnoreCase("off")|| args[2].equalsIgnoreCase("disabled")) {
|
||||
toggle = false;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("loot")) {
|
||||
playerParty.setSharingLootDrops(toggle);
|
||||
}
|
||||
else if (args[1].equalsIgnoreCase("mining")) {
|
||||
playerParty.setSharingMiningDrops(toggle);
|
||||
}
|
||||
else if (args[1].equalsIgnoreCase("herbalism")) {
|
||||
playerParty.setSharingHerbalismDrops(toggle);
|
||||
}
|
||||
else if (args[1].equalsIgnoreCase("woodcutting")) {
|
||||
playerParty.setSharingWoodcuttingDrops(toggle);
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting> <true | false>"));
|
||||
}
|
||||
notifyToggleItemShareCategory((Player) sender, args, toggle);
|
||||
return true;
|
||||
|
||||
default:
|
||||
// sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | EQUAL | RANDOM>"));
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | RANDOM>"));
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | EQUAL | RANDOM>"));
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting> <true | false>"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -57,4 +85,15 @@ public class PartyItemShareCommand implements CommandExecutor {
|
||||
member.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Item"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString()))));
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyToggleItemShareCategory(Player sender, String[] args, boolean toggle) {
|
||||
String state = "disabled";
|
||||
if (toggle) {
|
||||
state = "enabled";
|
||||
}
|
||||
|
||||
for (Player member : playerParty.getOnlineMembers()) {
|
||||
member.sendMessage(LocaleLoader.getString("Commands.Party.ToggleShareCategory", StringUtils.getCapitalized(args[1]), state));
|
||||
}
|
||||
}
|
||||
}
|
@ -579,16 +579,23 @@ public class ItemChecks {
|
||||
case POTATO:
|
||||
case COCOA:
|
||||
case NETHER_WARTS:
|
||||
case APPLE:
|
||||
case BROWN_MUSHROOM:
|
||||
case RED_MUSHROOM:
|
||||
case RED_ROSE:
|
||||
case YELLOW_FLOWER:
|
||||
case CACTUS:
|
||||
case SUGAR_CANE:
|
||||
//TODO Add the rest
|
||||
case MELON:
|
||||
case PUMPKIN:
|
||||
case WATER_LILY:
|
||||
case VINE:
|
||||
return true;
|
||||
|
||||
case INK_SACK:
|
||||
if (is.getData().getData() == DyeColor.BROWN.getDyeData()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -635,6 +642,7 @@ public class ItemChecks {
|
||||
case LOG:
|
||||
case LEAVES:
|
||||
case SAPLING:
|
||||
case APPLE:
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
16
src/main/resources/itemweights.yml
Normal file
16
src/main/resources/itemweights.yml
Normal file
@ -0,0 +1,16 @@
|
||||
Item_Weights:
|
||||
Default: 5
|
||||
Emerald: 150
|
||||
Emerald_Ore: 150
|
||||
Diamond: 100
|
||||
Diamond_Ore: 100
|
||||
Gold_Ingot: 50
|
||||
Gold_Ore: 50
|
||||
Iron_Ingot: 40
|
||||
Iron_Ore: 40
|
||||
Lapis_Ore: 30
|
||||
Redstone: 30
|
||||
Redstone_Ore: 30
|
||||
Glowstone_Dust: 20
|
||||
Coal: 10
|
||||
Coal_Ore: 10
|
@ -452,6 +452,7 @@ Commands.Party.Status=[[DARK_GRAY]]NAME: [[WHITE]]{0} {1}
|
||||
Commands.Party.ShareMode=[[DARK_GRAY]]SHARE MODE:
|
||||
Commands.Party.ItemShare=[[GRAY]]ITEM [[DARK_AQUA]]({0})
|
||||
Commands.Party.ExpShare=[[GRAY]]EXP [[DARK_AQUA]]({0})
|
||||
Commands.Party.ItemShareCategories=[[DARK_GRAY]]Sharing Items: [[GRAY]][[ITALIC]]{0}
|
||||
Commands.Party.MembersNear=[[DARK_GRAY]]NEAR YOU [[DARK_AQUA]]{0}[[DARK_GRAY]]/[[DARK_AQUA]]{1}
|
||||
Commands.Party.Accept=[[RED]]- Accept party invite
|
||||
Commands.Party.Chat.Off=Party Chat only [[RED]]Off
|
||||
@ -465,6 +466,7 @@ Commands.Party.Join=[[GRAY]]Joined Party: {0}
|
||||
Commands.Party.Create=[[GRAY]]Created Party: {0}
|
||||
Commands.Party.Rename=[[GRAY]]Party name changed to: [[WHITE]]{0}
|
||||
Commands.Party.SetSharing=[[GRAY]]Party {0} sharing set to: [[DARK_AQUA]]{1}
|
||||
Commands.Party.ToggleShareCategory=[[GRAY]]Party item sharing for [[GOLD]]{0} [[GRAY]]has been [[DARK_AQUA]]{1}
|
||||
Commands.Party.AlreadyExists=[[DARK_RED]]Party {0} already exists!
|
||||
Commands.Party.Kick=[[RED]]You were kicked from party {0}!
|
||||
Commands.Party.Leave=[[RED]]You have left that party
|
||||
|
Loading…
Reference in New Issue
Block a user