Updates to gamemode command, mode is now mandatory [creative|survival|adventure]
Updates to gamemode sign, now requires another line with gamemode
This commit is contained in:
ementalo 2012-08-02 13:48:13 +01:00
parent a1ac58d17c
commit 766f9b4dbd
9 changed files with 92 additions and 27 deletions

View file

@ -67,7 +67,7 @@ import org.yaml.snakeyaml.error.YAMLException;
public class Essentials extends JavaPlugin implements IEssentials public class Essentials extends JavaPlugin implements IEssentials
{ {
public static final int BUKKIT_VERSION = 2149; public static final int BUKKIT_VERSION = 2267;
private static final Logger LOGGER = Logger.getLogger("Minecraft"); private static final Logger LOGGER = Logger.getLogger("Minecraft");
private transient ISettings settings; private transient ISettings settings;
private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this); private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this);

View file

@ -1051,4 +1051,22 @@ public class OfflinePlayer implements Player
{ {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
@Override
public int getExpToLevel()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean hasLineOfSight(Entity entity)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isValid()
{
throw new UnsupportedOperationException("Not supported yet.");
}
} }

View file

@ -19,24 +19,27 @@ public class Commandgamemode extends EssentialsCommand
@Override @Override
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{ {
if (args.length < 1) if (args.length < 2)
{ {
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
gamemodeOtherPlayers(server, sender, args); gamemodeOtherPlayers(server, sender, args);
} }
@Override @Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{ {
if (args.length > 0 && args[0].trim().length() > 2 && user.isAuthorized("essentials.gamemode.others")) if(args.length < 1)
{
throw new NotEnoughArgumentsException();
}
if (args.length > 1 && args[0].trim().length() > 2 && user.isAuthorized("essentials.gamemode.others"))
{ {
gamemodeOtherPlayers(server, user, args); gamemodeOtherPlayers(server, user, args);
return; return;
} }
performSetMode(args[0], user);
user.setGameMode(user.getGameMode() == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL);
user.sendMessage(_("gameMode", _(user.getGameMode().toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName())); user.sendMessage(_("gameMode", _(user.getGameMode().toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName()));
} }
@ -49,23 +52,24 @@ public class Commandgamemode extends EssentialsCommand
{ {
continue; continue;
} }
performSetMode(args[1], player);
if (args.length > 1)
{
if (args[1].contains("creat") || args[1].equalsIgnoreCase("1"))
{
player.setGameMode(GameMode.CREATIVE);
}
else
{
player.setGameMode(GameMode.SURVIVAL);
}
}
else
{
player.setGameMode(player.getGameMode() == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL);
}
sender.sendMessage(_("gameMode", _(player.getGameMode().toString().toLowerCase(Locale.ENGLISH)), player.getDisplayName())); sender.sendMessage(_("gameMode", _(player.getGameMode().toString().toLowerCase(Locale.ENGLISH)), player.getDisplayName()));
} }
} }
private void performSetMode(String mode, Player player)
{
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);
}
}
} }

View file

@ -669,4 +669,10 @@ public class FakeWorld implements World
{ {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
@Override
public Entity spawnEntity(Location lctn, EntityType et)
{
throw new UnsupportedOperationException("Not supported yet.");
}
} }

View file

@ -7,6 +7,7 @@ import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import java.util.Locale; import java.util.Locale;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player;
public class SignGameMode extends EssentialsSign public class SignGameMode extends EssentialsSign
@ -27,11 +28,35 @@ public class SignGameMode extends EssentialsSign
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
{ {
final Trade charge = getTrade(sign, 1, ess); final Trade charge = getTrade(sign, 1, ess);
final String mode = sign.getLine(2).trim();
if(mode.isEmpty())
{
throw new SignException(_("invalidSignLine", 3));
}
charge.isAffordableFor(player); charge.isAffordableFor(player);
player.setGameMode(player.getGameMode() == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL); performSetMode(mode, player);
player.sendMessage(_("gameMode", _(player.getGameMode().toString().toLowerCase(Locale.ENGLISH)), player.getDisplayName())); player.sendMessage(_("gameMode", _(player.getGameMode().toString().toLowerCase(Locale.ENGLISH)), player.getDisplayName()));
charge.charge(player); charge.charge(player);
return true; return true;
} }
private void performSetMode(String mode, Player player)
{
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);
}
}
} }

View file

@ -117,7 +117,7 @@ commands:
aliases: [efireball] aliases: [efireball]
gamemode: gamemode:
description: Change player gamemode. description: Change player gamemode.
usage: /<command> [player] usage: /<command> [player] <creative|survival|adventure>
aliases: [gm,creative,creativemode,egamemode,ecreative,ecreativemode,egm] aliases: [gm,creative,creativemode,egamemode,ecreative,ecreativemode,egm]
getpos: getpos:
description: Get your current coordinates or those of a player. description: Get your current coordinates or those of a player.

View file

@ -741,4 +741,16 @@ public class FakeServer implements Server
{ {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
@Override
public boolean isPrimaryThread()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getMotd()
{
throw new UnsupportedOperationException("Not supported yet.");
}
} }

Binary file not shown.

Binary file not shown.