2011-11-16 00:21:55 +00:00
|
|
|
package com.earth2me.essentials.signs;
|
|
|
|
|
2011-11-21 01:55:26 +00:00
|
|
|
import com.earth2me.essentials.ChargeException;
|
2014-03-20 15:54:07 +00:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
2011-11-21 01:55:26 +00:00
|
|
|
import com.earth2me.essentials.Trade;
|
|
|
|
import com.earth2me.essentials.User;
|
|
|
|
import java.util.Locale;
|
2013-10-11 02:44:41 +00:00
|
|
|
import net.ess3.api.IEssentials;
|
2011-11-16 00:21:55 +00:00
|
|
|
import org.bukkit.GameMode;
|
2012-08-02 12:48:13 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2011-11-16 00:21:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
public class SignGameMode extends EssentialsSign
|
|
|
|
{
|
|
|
|
public SignGameMode()
|
|
|
|
{
|
|
|
|
super("GameMode");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
|
2012-08-06 01:44:01 +00:00
|
|
|
{
|
2012-08-05 23:23:47 +00:00
|
|
|
final String gamemode = sign.getLine(1);
|
|
|
|
if (gamemode.isEmpty())
|
|
|
|
{
|
|
|
|
sign.setLine(1, "Survival");
|
|
|
|
}
|
2012-08-06 01:44:01 +00:00
|
|
|
|
2012-08-05 23:23:47 +00:00
|
|
|
validateTrade(sign, 2, ess);
|
2012-08-06 01:44:01 +00:00
|
|
|
|
2011-11-16 00:21:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
|
|
|
|
{
|
2012-08-05 23:23:47 +00:00
|
|
|
final Trade charge = getTrade(sign, 2, ess);
|
|
|
|
final String mode = sign.getLine(1).trim();
|
2012-08-03 08:36:50 +00:00
|
|
|
|
|
|
|
if (mode.isEmpty())
|
2012-08-02 12:48:13 +00:00
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
throw new SignException(tl("invalidSignLine", 2));
|
2012-08-02 12:48:13 +00:00
|
|
|
}
|
2012-08-03 08:36:50 +00:00
|
|
|
|
2011-11-16 00:21:55 +00:00
|
|
|
charge.isAffordableFor(player);
|
|
|
|
|
2013-07-07 11:11:57 +00:00
|
|
|
performSetMode(mode.toLowerCase(Locale.ENGLISH), player.getBase());
|
2014-04-13 00:01:49 +00:00
|
|
|
player.sendMessage(tl("gameMode", tl(player.getBase().getGameMode().toString().toLowerCase(Locale.ENGLISH)), player.getDisplayName()));
|
2013-02-28 03:15:21 +00:00
|
|
|
Trade.log("Sign", "gameMode", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
|
2011-11-16 00:21:55 +00:00
|
|
|
charge.charge(player);
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-03 08:36:50 +00:00
|
|
|
|
2012-08-05 23:23:47 +00:00
|
|
|
private void performSetMode(String mode, Player player) throws SignException
|
2012-08-02 12:48:13 +00:00
|
|
|
{
|
2012-08-03 08:36:50 +00:00
|
|
|
if (mode.contains("survi") || mode.equalsIgnoreCase("0"))
|
|
|
|
{
|
|
|
|
player.setGameMode(GameMode.SURVIVAL);
|
|
|
|
}
|
|
|
|
else if (mode.contains("creat") || mode.equalsIgnoreCase("1"))
|
|
|
|
{
|
|
|
|
player.setGameMode(GameMode.CREATIVE);
|
|
|
|
}
|
|
|
|
else if (mode.contains("advent") || mode.equalsIgnoreCase("2"))
|
|
|
|
{
|
|
|
|
player.setGameMode(GameMode.ADVENTURE);
|
|
|
|
}
|
2012-08-06 01:44:01 +00:00
|
|
|
else
|
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
throw new SignException(tl("invalidSignLine", 2));
|
2012-08-05 23:23:47 +00:00
|
|
|
}
|
2012-08-02 12:48:13 +00:00
|
|
|
}
|
2011-11-16 00:21:55 +00:00
|
|
|
}
|