mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-12-26 02:28:03 +01:00
Combine our placedAnvil checks into one function.
This commit is contained in:
parent
08960a2dbc
commit
6b18cec7fb
@ -28,7 +28,9 @@ import com.gmail.nossr50.skills.excavation.ExcavationManager;
|
||||
import com.gmail.nossr50.skills.fishing.FishingManager;
|
||||
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
||||
import com.gmail.nossr50.skills.mining.MiningManager;
|
||||
import com.gmail.nossr50.skills.repair.Repair;
|
||||
import com.gmail.nossr50.skills.repair.RepairManager;
|
||||
import com.gmail.nossr50.skills.repair.Salvage;
|
||||
import com.gmail.nossr50.skills.smelting.SmeltingManager;
|
||||
import com.gmail.nossr50.skills.swords.SwordsManager;
|
||||
import com.gmail.nossr50.skills.taming.TamingManager;
|
||||
@ -66,7 +68,7 @@ public class McMMOPlayer {
|
||||
private boolean displaySkillNotifications = true;
|
||||
|
||||
private boolean abilityUse = true;
|
||||
private boolean placedAnvil;
|
||||
private boolean placedRepairAnvil;
|
||||
private boolean placedSalvageAnvil;
|
||||
private boolean godMode;
|
||||
|
||||
@ -313,24 +315,26 @@ public class McMMOPlayer {
|
||||
* Repair Anvil Placement
|
||||
*/
|
||||
|
||||
public void togglePlacedAnvil() {
|
||||
placedAnvil = !placedAnvil;
|
||||
public boolean getPlacedAnvil(int anvilId) {
|
||||
if (anvilId == Repair.anvilID) {
|
||||
return placedRepairAnvil;
|
||||
}
|
||||
|
||||
if (anvilId == Salvage.anvilID) {
|
||||
return placedSalvageAnvil;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Boolean getPlacedAnvil() {
|
||||
return placedAnvil;
|
||||
}
|
||||
public void togglePlacedAnvil(int anvilId) {
|
||||
if (anvilId == Repair.anvilID) {
|
||||
placedRepairAnvil = !placedRepairAnvil;
|
||||
}
|
||||
|
||||
/*
|
||||
* Salvage Anvil Placement
|
||||
*/
|
||||
|
||||
public void togglePlacedSalvageAnvil() {
|
||||
placedSalvageAnvil = !placedSalvageAnvil;
|
||||
}
|
||||
|
||||
public Boolean getPlacedSalvageAnvil() {
|
||||
return placedSalvageAnvil;
|
||||
if (anvilId == Salvage.anvilID) {
|
||||
placedSalvageAnvil = !placedSalvageAnvil;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -35,6 +35,7 @@ import com.gmail.nossr50.skills.excavation.ExcavationManager;
|
||||
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
||||
import com.gmail.nossr50.skills.mining.MiningManager;
|
||||
import com.gmail.nossr50.skills.repair.Repair;
|
||||
import com.gmail.nossr50.skills.repair.Salvage;
|
||||
import com.gmail.nossr50.skills.smelting.SmeltingManager;
|
||||
import com.gmail.nossr50.skills.unarmed.Unarmed;
|
||||
import com.gmail.nossr50.skills.woodcutting.Woodcutting;
|
||||
@ -108,14 +109,15 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
|
||||
BlockState blockState = event.getBlock().getState();
|
||||
int blockId = blockState.getTypeId();
|
||||
|
||||
/* Check if the blocks placed should be monitored so they do not give out XP in the future */
|
||||
if (BlockUtils.shouldBeWatched(blockState)) {
|
||||
mcMMO.placeStore.setTrue(blockState);
|
||||
}
|
||||
|
||||
if (Repair.anvilMessagesEnabled) {
|
||||
UserManager.getPlayer(player).getRepairManager().placedAnvilCheck(blockState.getTypeId());
|
||||
if (Repair.anvilMessagesEnabled && (blockId == Repair.anvilID || blockId == Salvage.anvilID)) {
|
||||
UserManager.getPlayer(player).getRepairManager().placedAnvilCheck(blockId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
|
||||
public class Repair {
|
||||
// The order of the values is extremely important, a few methods depend on it to work properly
|
||||
@ -111,4 +112,28 @@ public class Repair {
|
||||
|
||||
inventory.removeItem(item);
|
||||
}
|
||||
|
||||
protected static String[] getSpoutAnvilMessages(int blockId) {
|
||||
if (blockId == Repair.anvilID) {
|
||||
return new String[] {LocaleLoader.getString("Repair.AnvilPlaced.Spout1"), LocaleLoader.getString("Repair.AnvilPlaced.Spout2")};
|
||||
}
|
||||
|
||||
if (blockId == Salvage.anvilID) {
|
||||
return new String[] {"[mcMMO] Anvil Placed", "Right click to salvage!"};
|
||||
}
|
||||
|
||||
return new String[] {"", ""};
|
||||
}
|
||||
|
||||
protected static String getAnvilMessage(int blockId) {
|
||||
if (blockId == Repair.anvilID) {
|
||||
return LocaleLoader.getString("Repair.Listener.Anvil");
|
||||
}
|
||||
|
||||
if (blockId == Salvage.anvilID) {
|
||||
return LocaleLoader.getString("Repair.Listener.Anvil2");
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
@ -32,24 +32,15 @@ public class RepairManager extends SkillManager {
|
||||
super(mcMMOPlayer, SkillType.REPAIR);
|
||||
}
|
||||
|
||||
public void placedAnvilCheck(int anvilId) {
|
||||
if (anvilId == Repair.anvilID) {
|
||||
repairAnvilCheck(anvilId);
|
||||
}
|
||||
else if (anvilId == Salvage.anvilID) {
|
||||
salvageAnvilCheck(anvilId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles notifications for placing an anvil.
|
||||
*
|
||||
* @param anvilID The item ID of the anvil block
|
||||
*/
|
||||
public void repairAnvilCheck(int anvilID) {
|
||||
public void placedAnvilCheck(int anvilId) {
|
||||
Player player = getPlayer();
|
||||
|
||||
if (mcMMOPlayer.getPlacedAnvil()) {
|
||||
if (mcMMOPlayer.getPlacedAnvil(anvilId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -57,41 +48,19 @@ public class RepairManager extends SkillManager {
|
||||
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
||||
|
||||
if (spoutPlayer.isSpoutCraftEnabled()) {
|
||||
spoutPlayer.sendNotification(LocaleLoader.getString("Repair.AnvilPlaced.Spout1"), LocaleLoader.getString("Repair.AnvilPlaced.Spout2"), Material.getMaterial(anvilID));
|
||||
String[] spoutMessages = Repair.getSpoutAnvilMessages(anvilId);
|
||||
spoutPlayer.sendNotification(spoutMessages[0], spoutMessages[1], Material.getMaterial(anvilId));
|
||||
}
|
||||
else {
|
||||
player.sendMessage(Repair.getAnvilMessage(anvilId));
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Listener.Anvil"));
|
||||
player.sendMessage(Repair.getAnvilMessage(anvilId));
|
||||
}
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
|
||||
mcMMOPlayer.togglePlacedAnvil();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles notifications for placing an anvil.
|
||||
*
|
||||
* @param player The player placing the anvil
|
||||
* @param anvilID The item ID of the anvil block
|
||||
*/
|
||||
public void salvageAnvilCheck(int anvilID) {
|
||||
Player player = getPlayer();
|
||||
|
||||
if (!mcMMOPlayer.getPlacedSalvageAnvil()) {
|
||||
if (mcMMO.spoutEnabled) {
|
||||
final SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
||||
|
||||
if (spoutPlayer.isSpoutCraftEnabled()) {
|
||||
spoutPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to salvage!", Material.getMaterial(anvilID));
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Listener.Anvil2"));
|
||||
}
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
|
||||
mcMMOPlayer.togglePlacedSalvageAnvil();
|
||||
}
|
||||
mcMMOPlayer.togglePlacedAnvil(anvilId);
|
||||
}
|
||||
|
||||
public void handleRepair(ItemStack item) {
|
||||
|
Loading…
Reference in New Issue
Block a user