本文整理汇总了Java中net.minecraft.world.GameRules.setOrCreateGameRule方法的典型用法代码示例。如果您正苦于以下问题:Java GameRules.setOrCreateGameRule方法的具体用法?Java GameRules.setOrCreateGameRule怎么用?Java GameRules.setOrCreateGameRule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.world.GameRules
的用法示例。
在下文中一共展示了GameRules.setOrCreateGameRule方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rainOverrideGR
import net.minecraft.world.GameRules; //导入方法依赖的package包/类
@SubscribeEvent(priority = EventPriority.NORMAL)
public void rainOverrideGR (TickEvent.ServerTickEvent event) {
WorldInfo worldinfo = GameInfo.worldInfo;
GameRules gameRules = GameInfo.gameRules;
try {
if (!gameRules.getBoolean("doWeather")) {
gameRules.setOrCreateGameRule("doWeather", "true");
gameRules.setOrCreateGameRule("doWeatherCycle", "false");
LogHelper.info("Switched weather GameRule over to Vanilla GameRule.");
}
}
catch (Exception e) {
LogHelper.error("Exception in RainOverride: " + e);
}
}
示例2: worldLoad
import net.minecraft.world.GameRules; //导入方法依赖的package包/类
@SubscribeEvent
public void worldLoad(WorldEvent.Load event) {
GameRules gameRule = event.world.getGameRules();
// if (createGameruleIfAbsent(gameRule, "pzKeepInventory", keepInventoryDefault)) {
// System.out.println("******** pzKeepInventory rule is not present, creating it.....");
//
// gameRule.setOrCreateGameRule("keepInventory", Boolean.toString(keepInventoryDefault));
// }
//createGameruleIfAbsent(gameRule, "dropInventory", dropInventoryDefault);
//createGameruleIfAbsent(gameRule, "dropHotbar", dropHotbarDefault);
//createGameruleIfAbsent(gameRule, "dropArmor", dropArmorDefault);
//createGameruleIfAbsent(gameRule, "dropXP", dropXPDefault);
gameRule.setOrCreateGameRule("keepInventory", Boolean.toString(keepInventoryDefault));
gameRule.setOrCreateGameRule("dropInventory", String.valueOf(dropInventoryDefault));
gameRule.setOrCreateGameRule("dropHotbar", String.valueOf(dropHotbarDefault));
gameRule.setOrCreateGameRule("dropArmor", String.valueOf(dropArmorDefault));
gameRule.setOrCreateGameRule("dropXP", String.valueOf(dropXPDefault));
}
示例3: processCommand
import net.minecraft.world.GameRules; //导入方法依赖的package包/类
/**
* Callback when the command is invoked
*/
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
GameRules gamerules = this.getGameRules();
String s = args.length > 0 ? args[0] : "";
String s1 = args.length > 1 ? buildString(args, 1) : "";
switch (args.length)
{
case 0:
sender.addChatMessage(new ChatComponentText(joinNiceString(gamerules.getRules())));
break;
case 1:
if (!gamerules.hasRule(s))
{
throw new CommandException("commands.gamerule.norule", new Object[] {s});
}
String s2 = gamerules.getString(s);
sender.addChatMessage((new ChatComponentText(s)).appendText(" = ").appendText(s2));
sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, gamerules.getInt(s));
break;
default:
if (gamerules.areSameType(s, GameRules.ValueType.BOOLEAN_VALUE) && !"true".equals(s1) && !"false".equals(s1))
{
throw new CommandException("commands.generic.boolean.invalid", new Object[] {s1});
}
gamerules.setOrCreateGameRule(s, s1);
func_175773_a(gamerules, s);
notifyOperators(sender, this, "commands.gamerule.success", new Object[0]);
}
}
示例4: execute
import net.minecraft.world.GameRules; //导入方法依赖的package包/类
/**
* Callback for when the command is executed
*/
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
GameRules gamerules = this.getOverWorldGameRules(server);
String s = args.length > 0 ? args[0] : "";
String s1 = args.length > 1 ? buildString(args, 1) : "";
switch (args.length)
{
case 0:
sender.addChatMessage(new TextComponentString(joinNiceString(gamerules.getRules())));
break;
case 1:
if (!gamerules.hasRule(s))
{
throw new CommandException("commands.gamerule.norule", new Object[] {s});
}
String s2 = gamerules.getString(s);
sender.addChatMessage((new TextComponentString(s)).appendText(" = ").appendText(s2));
sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, gamerules.getInt(s));
break;
default:
if (gamerules.areSameType(s, GameRules.ValueType.BOOLEAN_VALUE) && !"true".equals(s1) && !"false".equals(s1))
{
throw new CommandException("commands.generic.boolean.invalid", new Object[] {s1});
}
gamerules.setOrCreateGameRule(s, s1);
notifyGameRuleChange(gamerules, s, server);
notifyCommandListener(sender, this, "commands.gamerule.success", new Object[] {s, s1});
}
}
示例5: execute
import net.minecraft.world.GameRules; //导入方法依赖的package包/类
/**
* Callback for when the command is executed
*/
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
GameRules gamerules = this.getOverWorldGameRules(server);
String s = args.length > 0 ? args[0] : "";
String s1 = args.length > 1 ? buildString(args, 1) : "";
switch (args.length)
{
case 0:
sender.addChatMessage(new TextComponentString(joinNiceString(gamerules.getRules())));
break;
case 1:
if (!gamerules.hasRule(s))
{
throw new CommandException("commands.gamerule.norule", new Object[] {s});
}
String s2 = gamerules.getString(s);
sender.addChatMessage((new TextComponentString(s)).appendText(" = ").appendText(s2));
sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, gamerules.getInt(s));
break;
default:
if (gamerules.areSameType(s, GameRules.ValueType.BOOLEAN_VALUE) && !"true".equals(s1) && !"false".equals(s1))
{
throw new CommandException("commands.generic.boolean.invalid", new Object[] {s1});
}
gamerules.setOrCreateGameRule(s, s1);
notifyGameRuleChange(gamerules, s, server);
notifyCommandListener(sender, this, "commands.gamerule.success", new Object[] {s, s1});
}
}
示例6: worldLoad
import net.minecraft.world.GameRules; //导入方法依赖的package包/类
@SubscribeEvent
public void worldLoad(WorldEvent.Load event) {
GameRules gameRule = event.world.getGameRules();
if (createGameruleIfAbsent(gameRule, "pzKeepInventory", keepInventoryDefault)) {
gameRule.setOrCreateGameRule("keepInventory", Boolean.toString(keepInventoryDefault));
}
createGameruleIfAbsent(gameRule, "dropInventory", dropInventoryDefault);
createGameruleIfAbsent(gameRule, "dropHotbar", dropHotbarDefault);
createGameruleIfAbsent(gameRule, "dropArmor", dropArmorDefault);
createGameruleIfAbsent(gameRule, "dropXP", dropXPDefault);
}
示例7: serverStarted
import net.minecraft.world.GameRules; //导入方法依赖的package包/类
@SubscribeEvent
public void serverStarted(WorldEvent.Load event) {
if (!event.getWorld().isRemote && event.getWorld().provider.getDimension() == 0) {
logger.debug("Applying the game rules");
GameRules rules = event.getWorld().getGameRules();
for (Entry<String, String> entry : gameRules.entrySet()) {
rules.setOrCreateGameRule(entry.getKey(), entry.getValue());
}
}
}
示例8: processCommand
import net.minecraft.world.GameRules; //导入方法依赖的package包/类
public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
{
String var6;
if (par2ArrayOfStr.length == 2)
{
var6 = par2ArrayOfStr[0];
String var7 = par2ArrayOfStr[1];
GameRules var8 = this.getGameRules();
if (var8.hasRule(var6))
{
var8.setOrCreateGameRule(var6, var7);
notifyAdmins(par1ICommandSender, "commands.gamerule.success", new Object[0]);
}
else
{
notifyAdmins(par1ICommandSender, "commands.gamerule.norule", new Object[] {var6});
}
}
else if (par2ArrayOfStr.length == 1)
{
var6 = par2ArrayOfStr[0];
GameRules var4 = this.getGameRules();
if (var4.hasRule(var6))
{
String var5 = var4.getGameRuleStringValue(var6);
par1ICommandSender.addChatMessage((new ChatComponentText(var6)).appendText(" = ").appendText(var5));
}
else
{
notifyAdmins(par1ICommandSender, "commands.gamerule.norule", new Object[] {var6});
}
}
else if (par2ArrayOfStr.length == 0)
{
GameRules var3 = this.getGameRules();
par1ICommandSender.addChatMessage(new ChatComponentText(joinNiceString(var3.getRules())));
}
else
{
throw new WrongUsageException("commands.gamerule.usage", new Object[0]);
}
}
示例9: processCommand
import net.minecraft.world.GameRules; //导入方法依赖的package包/类
public void processCommand(ICommandSender p_71515_1_, String[] p_71515_2_)
{
String s1;
if (p_71515_2_.length == 2)
{
s1 = p_71515_2_[0];
String s2 = p_71515_2_[1];
GameRules gamerules2 = this.getGameRules();
if (gamerules2.hasRule(s1))
{
gamerules2.setOrCreateGameRule(s1, s2);
func_152373_a(p_71515_1_, this, "commands.gamerule.success", new Object[0]);
}
else
{
func_152373_a(p_71515_1_, this, "commands.gamerule.norule", new Object[] {s1});
}
}
else if (p_71515_2_.length == 1)
{
s1 = p_71515_2_[0];
GameRules gamerules1 = this.getGameRules();
if (gamerules1.hasRule(s1))
{
String s = gamerules1.getGameRuleStringValue(s1);
p_71515_1_.addChatMessage((new ChatComponentText(s1)).appendText(" = ").appendText(s));
}
else
{
func_152373_a(p_71515_1_, this, "commands.gamerule.norule", new Object[] {s1});
}
}
else if (p_71515_2_.length == 0)
{
GameRules gamerules = this.getGameRules();
p_71515_1_.addChatMessage(new ChatComponentText(joinNiceString(gamerules.getRules())));
}
else
{
throw new WrongUsageException("commands.gamerule.usage", new Object[0]);
}
}
示例10: processCommand
import net.minecraft.world.GameRules; //导入方法依赖的package包/类
public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
{
String s;
if (par2ArrayOfStr.length == 2)
{
s = par2ArrayOfStr[0];
String s1 = par2ArrayOfStr[1];
GameRules gamerules = this.getGameRules();
if (gamerules.hasRule(s))
{
gamerules.setOrCreateGameRule(s, s1);
notifyAdmins(par1ICommandSender, "commands.gamerule.success", new Object[0]);
}
else
{
notifyAdmins(par1ICommandSender, "commands.gamerule.norule", new Object[] {s});
}
}
else if (par2ArrayOfStr.length == 1)
{
s = par2ArrayOfStr[0];
GameRules gamerules1 = this.getGameRules();
if (gamerules1.hasRule(s))
{
String s2 = gamerules1.getGameRuleStringValue(s);
par1ICommandSender.sendChatToPlayer(ChatMessageComponent.createFromText(s).addText(" = ").addText(s2));
}
else
{
notifyAdmins(par1ICommandSender, "commands.gamerule.norule", new Object[] {s});
}
}
else if (par2ArrayOfStr.length == 0)
{
GameRules gamerules2 = this.getGameRules();
par1ICommandSender.sendChatToPlayer(ChatMessageComponent.createFromText(joinNiceString(gamerules2.getRules())));
}
else
{
throw new WrongUsageException("commands.gamerule.usage", new Object[0]);
}
}