@Test public void testDifficulty() throws InputException { Class[] inputTypes = {Difficulty.class, Difficulty.class}; String[] input = {"3", "peaceful"}; Object[] output = InputFormatter.getTypesFromInput(inputTypes, Arrays.asList(input), null); // First let's make sure we didn't lose anything, or get anything assertEquals(inputTypes.length, output.length); // Next let's make sure everything is the right type for (Object object : output) { assertTrue(object instanceof Difficulty); } // Finally, let's make sure the values are correct assertSame(output[0], Difficulty.HARD); assertSame(output[1], Difficulty.PEACEFUL); }
@Override public ModuleCollection load(Match match) { ModuleCollection<MapDifficulty> results = new ModuleCollection<>(); try { switch (NumUtils.parseInt(match.getDocument().getRootElement().getChildText("difficulty"))) { case 0: results.add(new MapDifficulty(Difficulty.PEACEFUL)); break; case 1: results.add(new MapDifficulty(Difficulty.EASY)); break; case 2: results.add(new MapDifficulty(Difficulty.NORMAL)); break; case 3: results.add(new MapDifficulty(Difficulty.HARD)); break; } } catch (NumberFormatException | NullPointerException e) { } return results; }
public void createWorld(String name, long seed, String generator, Environment env, WorldType type, boolean genStructures, boolean providedSeed) { name = name.toLowerCase(); World w = this.createBukkitWorld(name, seed, generator, env, type, genStructures, providedSeed); this.database.setValue("worlds." + name + ".seed", seed); if(generator != null) { this.database.setValue("worlds." + name + ".generator", generator); } this.database.setValue("worlds." + name + ".environment", env.name()); this.database.setValue("worlds." + name + ".type", type.name()); this.database.setValue("worlds." + name + ".generateStructures", genStructures); this.database.setValue("worlds." + name + ".pvp", false); this.database.setValue("worlds." + name + ".difficulty", Difficulty.EASY.name()); this.database.setValue("worlds." + name + ".gamemode", GameMode.SURVIVAL.name()); WorldData world = new WorldData(this.module, this, name); world.setWorld(w); this.worlds.put(name, world); }
public void onEnable() { if(plugin.getConfig().getInt("endPortalLocationEpisodeAnnounce") == 0) { String msg = "No value found for 'endPortalLocationEpisodeAnnounce', disabling end portal announce"; RftdLogger.log(Level.WARN, msg); endPortalLocationAnnounced = true; } Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard(); Objective objective = scoreboard.getObjective(DisplaySlot.SIDEBAR); if(objective != null) objective.unregister(); String eggLocationString = plugin.getConfig().getString("egg"); if(eggLocationString != null) { Location eggLocation = RftdHelper.stringToBlockLocation(eggLocationString); setEggLocation(eggLocation); } for(World world : Bukkit.getWorlds()) { world.setDifficulty(Difficulty.PEACEFUL); world.setFullTime(6000); world.setGameRuleValue("doDaylightCycle", "false"); } }
@Override public ModuleCollection<MapDifficulty> load(Match match) { ModuleCollection<MapDifficulty> results = new ModuleCollection<>(); try { switch (Numbers.parseInt(match.getDocument().getRootElement().getChildText("difficulty"))) { case 0: results.add(new MapDifficulty(Difficulty.PEACEFUL)); break; case 1: results.add(new MapDifficulty(Difficulty.EASY)); break; case 2: results.add(new MapDifficulty(Difficulty.NORMAL)); break; case 3: results.add(new MapDifficulty(Difficulty.HARD)); break; } } catch (NumberFormatException | NullPointerException e) { } return results; }
public static void apply(World world) { world.setKeepSpawnInMemory(true); world.setDifficulty(Difficulty.HARD); world.setStorm(false); world.setThundering(false); world.setWeatherDuration(9999999); world.setTime(6000); if (SkyApi.getSm().isDedicated()) { Bukkit.getServer().setDefaultGameMode(GameMode.ADVENTURE); } world.setGameRuleValue("doDaylightCycle", "false"); world.setGameRuleValue("doFireTick", "false"); world.setGameRuleValue("doMobSpawning", "false"); world.setGameRuleValue("mobGriefing", "false"); world.save(); world.setAutoSave(true); }
public PortalPair(String name, InstanceEntrancePortal enter, InstanceDestinationPortal destination, double entryPrice, double createPrice, ItemStack entryItem, ItemStack createItem, int unloadTime, int recreateTime, World.Environment environment, Difficulty difficulty, String defaultParty, Facing entranceFacing, Facing destinationFacing, int maxPlayers, int maxInstances) { this.name = name; this.enter = enter; this.destination = destination; this.entryPrice = entryPrice; this.entryItem = entryItem; this.createPrice = createPrice; this.createItem = createItem; this.unloadTime = unloadTime; this.recreateTime = recreateTime; this.environment = environment; this.difficulty = difficulty; this.defaultParty = defaultParty; this.maxPlayers = maxPlayers; this.maxInstances = maxInstances; enter.setFacing(entranceFacing); destination.setFacing(destinationFacing); enter.setPortalPair(this); destination.setPortalPair(this); }
@Override public List<String> execute(Instances instances, Player player, String[] args) { if (args.length != 1) { return null; } Session session = instances.getSession(player); if (session.getEntrance() == null) { throw new InvocationException("You have not set the entrance portal location."); } if (session.getDestination() == null) { throw new InvocationException("You have not set the destination portal location."); } if (instances.getPortalPair(args[0]) != null) { throw new InvocationException("That portal pair already exists."); } InstanceEntrancePortal entrance = new InstanceEntrancePortal(session.getEntrance()); InstanceDestinationPortal destination = new InstanceDestinationPortal(session.getDestination()); World instanceWorld = instances.getServer().getWorld(destination.getCuboid().getWorld()); World.Environment environment = instanceWorld.getEnvironment(); Difficulty difficulty = instanceWorld.getDifficulty(); PortalPair pair = new PortalPair(args[0], entrance, destination, environment, difficulty); instances.addPortalPair(pair); session.clear(); return msg("Portal " + args[0] + " created."); }
public MapInfo(SemanticVersion proto, @Nullable String slug, String name, SemanticVersion version, MapDoc.Edition edition, MapDoc.Phase phase, @Nullable BaseComponent game, MapDoc.Genre genre, Set<MapDoc.Gamemode> gamemodes, BaseComponent objective, List<Contributor> authors, List<Contributor> contributors, List<String> rules, @Nullable Difficulty difficulty, Environment dimension, boolean friendlyFire) { this.id = new MapId(slug != null ? slug : MapId.slugifyName(name), edition, phase); this.proto = checkNotNull(proto); this.name = checkNotNull(name); this.version = checkNotNull(version); this.game = game; this.genre = checkNotNull(genre); this.gamemodes = checkNotNull(gamemodes); this.objective = checkNotNull(objective); this.authors = checkNotNull(authors); this.contributors = checkNotNull(contributors); this.rules = checkNotNull(rules); this.difficulty = difficulty; this.dimension = checkNotNull(dimension); this.friendlyFire = friendlyFire; }
public boolean loadMap(int gNumber) { WorldController wc = SkyWarsReloaded.getWC(); String mapName = name + "_" + gNumber; boolean mapExists = false; File target = new File(rootDirectory, mapName); if(target.isDirectory()) { if(target.list().length > 0) { mapExists = true; } } if (mapExists) { SkyWarsReloaded.getWC().deleteWorld(mapName); } wc.copyWorld(source, target); boolean loaded = SkyWarsReloaded.getWC().loadWorld(mapName); if (loaded) { World world = SkyWarsReloaded.get().getServer().getWorld(mapName); world.setAutoSave(false); world.setThundering(false); world.setStorm(false); world.setDifficulty(Difficulty.NORMAL); world.setSpawnLocation(2000, 0, 2000); world.setTicksPerAnimalSpawns(1); world.setTicksPerMonsterSpawns(1); world.setGameRuleValue("doMobSpawning", "false"); world.setGameRuleValue("mobGriefing", "false"); world.setGameRuleValue("doFireTick", "false"); world.setGameRuleValue("showDeathMessages", "false"); } return loaded; }
public void prepareWorld(World w) { w.setPVP(true); w.setGameRuleValue("doDaylightCycle", "false"); w.setStorm(false); w.setDifficulty(Difficulty.PEACEFUL); w.setTime(14000); w.getLivingEntities().stream().filter(e -> !e.getType().equals(EntityType.PLAYER)).forEach(Entity::remove); initArena(); w.setAutoSave(false); }
@Override public void onLoad() { add(Difficulty.PEACEFUL, "Peaceful", "0", "P", "Pe"); add(Difficulty.EASY, "Easy", "1", "E", "Ez", "Es"); add(Difficulty.NORMAL, "Normal", "2", "N", "No", "Norm", "Default", "Def"); add(Difficulty.HARD, "Hard", "3", "H", "Ha"); }
public Difficulty getDifficulty() { if (this.hasDifficulty()) { return this.difficulty; } return DEFAULT_DIFFICULTY; }
private Difficulty parseDifficulty(Element parent) { if (parent != null) { return XMLDifficulty.parse(parent, Difficulty.PEACEFUL); } return null; }
public static Difficulty parse(Element xml, Difficulty def) { Difficulty difficulty = parse(xml); if (difficulty != null) { return difficulty; } return def; }
public static Difficulty parse(Attribute xml) { if (xml != null) { return parse(xml.getValue()); } return null; }
public static Difficulty parse(Attribute xml, Difficulty def) { Difficulty difficulty = parse(xml); if (difficulty != null) { return difficulty; } return def; }
public static Difficulty parse(String value, Difficulty def) { Difficulty result = null; if (value != null) { try { result = Difficulty.getByValue(Integer.parseInt(value)); } catch (NumberFormatException ex) { result = Difficulty.valueOf(parseEnumValue(value)); } } if (result != null) { return result; } return def; }
@Override public boolean execute(CommandSender sender, String currentAlias, String[] args) { if (!testPermission(sender)) return true; if (args.length != 1 || args[0].length() == 0) { sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); return false; } Difficulty difficulty = Difficulty.getByValue(getDifficultyForString(sender, args[0])); if (Bukkit.isHardcore()) { difficulty = Difficulty.HARD; } Bukkit.getWorlds().get(0).setDifficulty(difficulty); int levelCount = 1; if (Bukkit.getAllowNether()) { Bukkit.getWorlds().get(levelCount).setDifficulty(difficulty); levelCount++; } if (Bukkit.getAllowEnd()) { Bukkit.getWorlds().get(levelCount).setDifficulty(difficulty); } Command.broadcastCommandMessage(sender, "Set difficulty to " + difficulty.toString()); return true; }
@EventHandler(ignoreCancelled=1, priority=EventPriority.MONITOR) public void onHeal(EntityRegainHealthEvent event) { if (!event.getRegainReason().equals((Object)EntityRegainHealthEvent.RegainReason.SATIATED)) { return; } if (!(event.getEntity() instanceof Player)) { return; } Player player = (Player)event.getEntity(); if (player.getWorld().getDifficulty().equals((Object)Difficulty.PEACEFUL)) { return; } int Count = 0; long Time = System.currentTimeMillis(); if (this.FastHealTicks.containsKey(player.getUniqueId())) { Count = this.FastHealTicks.get(player.getUniqueId()).getKey(); Time = this.FastHealTicks.get(player.getUniqueId()).getValue(); } if (this.checkFastHeal(player)) { this.getJanitor().logCheat(this, player, null, new String[0]); } if (this.FastHealTicks.containsKey(player.getUniqueId()) && UtilTime.elapsed(Time, 60000)) { Count = 0; Time = UtilTime.nowlong(); } this.LastHeal.put(player.getUniqueId(), System.currentTimeMillis()); this.FastHealTicks.put(player.getUniqueId(), new AbstractMap.SimpleEntry<Integer, Long>(Count, Time)); }
private void loadLobby() { uB = uA.getServer().createWorld(WorldCreator.name("uhc_lobby")); uB.setDifficulty(Difficulty.PEACEFUL); uB.setPVP(false); uB.setGameRuleValue("doDaylightCycle", "false"); uB.setGameRuleValue("keepInventory", "true"); uB.setGameRuleValue("randomTickSpeed", "0"); uB.setTime(6000); uB.setSpawnFlags(false, false); uB.setAutoSave(false); }
private void setDefaults(World world) { world.setAmbientSpawnLimit(0); world.setAnimalSpawnLimit(0); world.setAutoSave(true); world.setDifficulty(Difficulty.EASY); world.setGameRuleValue("doMobSpawning", "false"); world.setMonsterSpawnLimit(0); world.setPVP(true); world.setWaterAnimalSpawnLimit(0); world.setWeatherDuration(Integer.MAX_VALUE); }
private void createWorld() { isGenerating = true; world = WorldCreator.name("5min2live").type(WorldType.NORMAL) .environment(World.Environment.NORMAL).generateStructures(false).createWorld(); world.setDifficulty(Difficulty.HARD); final boolean pvpEnabled = fmtl.getConfig().getBoolean("pvp", false); world.setPVP(pvpEnabled); logInfo("PVP Enabled: " + pvpEnabled); eventNotifier.callEvent(new WorldReadyEvent(world)); isGenerating = false; }
public void start() { playing = true; starting = true; Title title = new Title("Tout le monde est prêt ?"); title.setTitleColor(ChatColor.DARK_AQUA); title.setSubtitle("On ne bouge plus !"); title.setSubtitleColor(ChatColor.AQUA); title.setFadeInTime(9); title.setStayTime(20); title.setFadeOutTime(9); title.setTimingsToTicks(); title.broadcast(); RftdLogger.log(Level.INFO, "Starting game..."); RftdHelper.setDifficulty(Difficulty.HARD); RftdHelper.canEveryoneWalk(false); RftdHelper.setEveryoneGameMode(GameMode.ADVENTURE); RftdHelper.setAnimalSpawnLimit(50); Collection<? extends Player> players = Bukkit.getOnlinePlayers(); for(Player player : players) { PlayerInventory inventory = player.getInventory(); inventory.clear(); inventory.setHelmet(null); inventory.setChestplate(null); inventory.setLeggings(null); inventory.setBoots(null); ItemStack endereyes = new ItemStack(Material.EYE_OF_ENDER, getEyeOfEnderQty()); inventory.setItem(4, endereyes); } task = Bukkit.getScheduler().runTaskTimer(plugin, new StartTimer(), 40, 20); }
public void init(List<Location> locs, List<BlockState> t2) { Bukkit.getServer().getWorld(name).setDifficulty(Difficulty.EASY); this.locs = locs; this.t2 = t2; for (Location l : locs) { for (Location loc : locs) { if (Math.abs(l.getBlockX()) - Math.abs(loc.getBlockX()) <= 2) { int radius = (int) (loc.distance(l) / 2); center = loc.subtract(radius, loc.getY(), loc.getZ()); } } } }
@Override public void onEnable() { // Initialize the potion effects list for (PotionEffectType type : potionTypes) potionEffects.add(new PotionEffect(type, Integer.MAX_VALUE, Byte.MAX_VALUE)); // Initialize the other class level fields this.configuration = this.getConfig(); this.scoreboard = this.getServer().getScoreboardManager().getMainScoreboard(); this.server = this.getServer(); this.world = this.getServer().getWorld("world"); // Deal with the configuration file this.saveDefaultConfig(); configuration.options().copyDefaults(true); this.saveConfig(); // Reset all of the scoreboard objectives if (scoreboard.getObjective("deaths") != null) scoreboard.getObjective("deaths").unregister(); if (scoreboard.getObjective("health") != null) scoreboard.getObjective("health").unregister(); if (scoreboard.getObjective("kills") != null) scoreboard.getObjective("kills").unregister(); // Prepare the server and world for pregame server.setDefaultGameMode(GameMode.SURVIVAL); server.setSpawnRadius(32); world.setDifficulty(Difficulty.HARD); world.setGameRuleValue("naturalRegeneration", "true"); world.setGameRuleValue("doDaylightCycle", "false"); world.setGameRuleValue("doMobSpawning", "false"); world.setGameRuleValue("spectatorsGenerateChunks", "false"); world.setFullTime(0); world.getWorldBorder().setCenter(world.getSpawnLocation().getX(), world.getSpawnLocation().getZ()); world.getWorldBorder().setSize(32); for (Entity entity : server.getWorld("world").getLivingEntities()) if (entity instanceof Monster) entity.remove(); // Set up the waiting list waiting.addAll(server.getOnlinePlayers()); // Register for events server.getPluginManager().registerEvents(this, this); }
public void start(int startRound, int startWave, int startDelay) { this.currentRound = startRound; this.currentWave = startWave; this.score = null; getWorld().setDifficulty(Difficulty.NORMAL); getWorld().setTime(15000L); getWorld().setMonsterSpawnLimit(0); clearArena(); // this.TaskId = new GameRunnable(this, startDelay).runTaskTimer(ZvP.getInstance(), 0L, 20L).getTaskId(); this.arenaMode.start(startDelay); ZvP.getPluginLogger().log(this.getClass(), Level.INFO, "Arena " + getID() + " started a new Task in mode " + this.arenaMode.getName() + "!", true); }
public void reStart(int startDelay) { getWorld().setDifficulty(Difficulty.NORMAL); getWorld().setTime(15000L); getWorld().setMonsterSpawnLimit(0); clearArena(); this.arenaMode = this.arenaMode.reInitialize(); this.arenaMode.start(startDelay); ZvP.getPluginLogger().log(this.getClass(), Level.INFO, "Arena " + getID() + " started a new Task in mode " + this.arenaMode.getName() + "!", true); }
public Difficulty parse(Instances instances, CommandSender sender, String[] args) { if (args.length != 1) { throw new InvocationException("You must specify a difficulty value for this property"); } try { return Difficulty.valueOf(args[0].toUpperCase()); } catch (IllegalArgumentException e) { throw new InvocationException("Difficulty must be peaceful, easy, normal or hard"); } }
public void setDifficulty(Difficulty difficulty) { this.getHandle().difficultySetting = net.minecraft.world.EnumDifficulty.getDifficultyEnum(difficulty.getValue()); }
public Difficulty getDifficulty() { return Difficulty.getByValue(this.getHandle().difficultySetting.ordinal()); }
@Override public InfoModule parse(MapModuleContext context, Logger logger, Document doc) throws InvalidXMLException { Element root = doc.getRootElement(); String name = Node.fromRequiredChildOrAttr(root, "name").getValueNormalize(); SemanticVersion version = XMLUtils.parseSemanticVersion(Node.fromRequiredChildOrAttr(root, "version")); MapDoc.Phase phase = XMLUtils.parseEnum(Node.fromLastChildOrAttr(root, "phase"), MapDoc.Phase.class, "phase", MapDoc.Phase.PRODUCTION); MapDoc.Edition edition = XMLUtils.parseEnum(Node.fromLastChildOrAttr(root, "edition"), MapDoc.Edition.class, "edition", MapDoc.Edition.STANDARD); // Allow multiple <objective> elements, so include files can provide defaults final BaseComponent objective = XMLUtils.parseLocalizedText(Node.fromRequiredLastChildOrAttr(root, "objective")); String slug = root.getChildTextNormalize("slug"); BaseComponent game = XMLUtils.parseFormattedText(root, "game"); MapDoc.Genre genre = XMLUtils.parseEnum(Node.fromNullable(root.getChild("genre")), MapDoc.Genre.class, "genre", MapDoc.Genre.OTHER); final TreeSet<MapDoc.Gamemode> gamemodes = new TreeSet<>(); for(Element elGamemode : root.getChildren("gamemode")) { gamemodes.add(XMLUtils.parseEnum(elGamemode, MapDoc.Gamemode.class)); } List<Contributor> authors = readContributorList(root, "authors", "author"); if(game == null) { Element blitz = root.getChild("blitz"); if(blitz != null) { Element title = blitz.getChild("title"); if(title != null) { if(context.getProto().isNoOlderThan(ProtoVersions.REMOVE_BLITZ_TITLE)) { throw new InvalidXMLException("<title> inside <blitz> is no longer supported, use <map game=\"...\">", title); } game = new Component(title.getTextNormalize()); } } } List<Contributor> contributors = readContributorList(root, "contributors", "contributor"); List<String> rules = new ArrayList<String>(); for(Element parent : root.getChildren("rules")) { for(Element rule : parent.getChildren("rule")) { rules.add(rule.getTextNormalize()); } } Difficulty difficulty = XMLUtils.parseEnum(Node.fromLastChildOrAttr(root, "difficulty"), Difficulty.class, "difficulty"); Environment dimension = XMLUtils.parseEnum(Node.fromLastChildOrAttr(root, "dimension"), Environment.class, "dimension", Environment.NORMAL); boolean friendlyFire = XMLUtils.parseBoolean(Node.fromLastChildOrAttr(root, "friendly-fire", "friendlyfire"), false); return new InfoModule(new MapInfo(context.getProto(), slug, name, version, edition, phase, game, genre, ImmutableSet.copyOf(gamemodes), objective, authors, contributors, rules, difficulty, dimension, friendlyFire)); }