mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-16 03:24:31 +02:00
Possible sign refactor?
This commit is contained in:
@@ -97,37 +97,31 @@ public class Trade
|
|||||||
|
|
||||||
public void pay(final IUser user)
|
public void pay(final IUser user)
|
||||||
{
|
{
|
||||||
pay(user, true);
|
try
|
||||||
|
{
|
||||||
|
pay(user, true);
|
||||||
|
}
|
||||||
|
catch (ChargeException ex)
|
||||||
|
{
|
||||||
|
//This should never ever get here... true above means items get dropped.
|
||||||
|
user.sendMessage(ex.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean pay(final IUser user, final boolean dropItems)
|
public void pay(final IUser user, final boolean dropItems) throws ChargeException
|
||||||
{
|
{
|
||||||
boolean success = true;
|
|
||||||
if (getMoney() != null && getMoney() > 0)
|
if (getMoney() != null && getMoney() > 0)
|
||||||
{
|
{
|
||||||
user.giveMoney(getMoney());
|
user.giveMoney(getMoney());
|
||||||
}
|
}
|
||||||
if (getItemStack() != null)
|
if (getItemStack() != null)
|
||||||
{
|
{
|
||||||
if (dropItems)
|
user.giveItems(itemStack, dropItems);
|
||||||
{
|
|
||||||
final Map<Integer, ItemStack> leftOver = InventoryWorkaround.addItem(user.getInventory(), true, getItemStack());
|
|
||||||
for (ItemStack itemStack : leftOver.values())
|
|
||||||
{
|
|
||||||
InventoryWorkaround.dropItem(user.getLocation(), itemStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success = InventoryWorkaround.addAllItems(user.getInventory(), true, getItemStack());
|
|
||||||
}
|
|
||||||
user.updateInventory();
|
|
||||||
}
|
}
|
||||||
if (getExperience() != null)
|
if (getExperience() != null)
|
||||||
{
|
{
|
||||||
SetExpFix.setTotalExperience(user, SetExpFix.getTotalExperience(user) + getExperience());
|
SetExpFix.setTotalExperience(user, SetExpFix.getTotalExperience(user) + getExperience());
|
||||||
}
|
}
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void charge(final IUser user) throws ChargeException
|
public void charge(final IUser user) throws ChargeException
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package com.earth2me.essentials.api;
|
package com.earth2me.essentials.api;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.ChargeException;
|
||||||
import com.earth2me.essentials.storage.IStorageObjectHolder;
|
import com.earth2me.essentials.storage.IStorageObjectHolder;
|
||||||
import com.earth2me.essentials.user.CooldownException;
|
import com.earth2me.essentials.user.CooldownException;
|
||||||
import com.earth2me.essentials.user.UserData;
|
import com.earth2me.essentials.user.UserData;
|
||||||
@@ -30,9 +31,9 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload,
|
|||||||
|
|
||||||
void giveMoney(double value, CommandSender initiator);
|
void giveMoney(double value, CommandSender initiator);
|
||||||
|
|
||||||
void giveItems(ItemStack itemStack, Boolean canSpew);
|
void giveItems(ItemStack itemStack, Boolean canSpew) throws ChargeException;
|
||||||
|
|
||||||
void giveItems(List<ItemStack> itemStacks, Boolean canSpew);
|
void giveItems(List<ItemStack> itemStacks, Boolean canSpew) throws ChargeException;
|
||||||
|
|
||||||
void setMoney(double value);
|
void setMoney(double value);
|
||||||
|
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package com.earth2me.essentials.user;
|
package com.earth2me.essentials.user;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.ChargeException;
|
||||||
import com.earth2me.essentials.Console;
|
import com.earth2me.essentials.Console;
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.Teleport;
|
import com.earth2me.essentials.Teleport;
|
||||||
@@ -654,7 +655,7 @@ public class User extends UserBase implements IUser
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void giveItems(ItemStack itemStack, Boolean canSpew)
|
public void giveItems(ItemStack itemStack, Boolean canSpew) throws ChargeException
|
||||||
{
|
{
|
||||||
if (giveItemStack(itemStack, canSpew))
|
if (giveItemStack(itemStack, canSpew))
|
||||||
{
|
{
|
||||||
@@ -663,7 +664,7 @@ public class User extends UserBase implements IUser
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void giveItems(List<ItemStack> itemStacks, Boolean canSpew)
|
public void giveItems(List<ItemStack> itemStacks, Boolean canSpew) throws ChargeException
|
||||||
{
|
{
|
||||||
boolean spew = false;
|
boolean spew = false;
|
||||||
for (ItemStack itemStack : itemStacks)
|
for (ItemStack itemStack : itemStacks)
|
||||||
@@ -679,7 +680,7 @@ public class User extends UserBase implements IUser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean giveItemStack(ItemStack itemStack, Boolean canSpew)
|
private boolean giveItemStack(ItemStack itemStack, Boolean canSpew) throws ChargeException
|
||||||
{
|
{
|
||||||
boolean spew = false;
|
boolean spew = false;
|
||||||
|
|
||||||
@@ -710,6 +711,11 @@ public class User extends UserBase implements IUser
|
|||||||
spew = true;
|
spew = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (!overfilled.isEmpty()) {
|
||||||
|
throw new ChargeException("Inventory full");
|
||||||
|
}
|
||||||
|
}
|
||||||
return spew;
|
return spew;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,10 +27,7 @@ public class SignBuy extends EssentialsSign
|
|||||||
final Trade items = getTrade(sign, 1, 2, player, ess);
|
final Trade items = getTrade(sign, 1, 2, player, ess);
|
||||||
final Trade charge = getTrade(sign, 3, ess);
|
final Trade charge = getTrade(sign, 3, ess);
|
||||||
charge.isAffordableFor(player);
|
charge.isAffordableFor(player);
|
||||||
if (!items.pay(player, false))
|
items.pay(player, false);
|
||||||
{
|
|
||||||
throw new ChargeException("Inventory full");
|
|
||||||
}
|
|
||||||
charge.charge(player);
|
charge.charge(player);
|
||||||
Trade.log("Sign", "Buy", "Interact", username, charge, username, items, sign.getBlock().getLocation(), ess);
|
Trade.log("Sign", "Buy", "Interact", username, charge, username, items, sign.getBlock().getLocation(), ess);
|
||||||
return true;
|
return true;
|
||||||
|
@@ -55,10 +55,7 @@ public class SignTrade extends EssentialsSign
|
|||||||
final Trade charge = getTrade(sign, 1, false, false, ess);
|
final Trade charge = getTrade(sign, 1, false, false, ess);
|
||||||
final Trade trade = getTrade(sign, 2, false, true, ess);
|
final Trade trade = getTrade(sign, 2, false, true, ess);
|
||||||
charge.isAffordableFor(player);
|
charge.isAffordableFor(player);
|
||||||
if (!trade.pay(player, false))
|
trade.pay(player, false);
|
||||||
{
|
|
||||||
throw new ChargeException("Full inventory");
|
|
||||||
}
|
|
||||||
substractAmount(sign, 2, trade, ess);
|
substractAmount(sign, 2, trade, ess);
|
||||||
addAmount(sign, 1, charge, ess);
|
addAmount(sign, 1, charge, ess);
|
||||||
charge.charge(player);
|
charge.charge(player);
|
||||||
|
Reference in New Issue
Block a user