本文整理汇总了Java中cn.nukkit.Server类的典型用法代码示例。如果您正苦于以下问题:Java Server类的具体用法?Java Server怎么用?Java Server使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Server类属于cn.nukkit包,在下文中一共展示了Server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResponse
import cn.nukkit.Server; //导入依赖的package包/类
private String getResponse(HttpURLConnection con) throws IOException {
InputStream is = null;
try {
is = con.getInputStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int bytesRead;
while ((bytesRead = is.read(b)) != -1) {
bos.write(b, 0, bytesRead);
}
return bos.toString();
} catch (IOException exception) {
this.sender.sendMessage(TextFormat.RED + "" + new TranslationContainer("nukkit.command.timings.reportError"));
Server.getInstance().getLogger().warning(con.getResponseMessage(), exception);
return null;
} finally {
if (is != null) {
is.close();
}
}
}
示例2: tick
import cn.nukkit.Server; //导入依赖的package包/类
/**
* Called every tick to count the number of times a timer caused TPS loss.
*/
static void tick() {
if (Timings.isTimingsEnabled()) {
boolean violated = Timings.fullServerTickTimer.isViolated();
for (Timing timing : TIMINGS) {
if (timing.isSpecial()) {
// Called manually
continue;
}
timing.tick(violated);
}
TimingsHistory.playerTicks += Server.getInstance().getOnlinePlayers().size();
TimingsHistory.timedTicks++;
}
}
示例3: setHistoryLength
import cn.nukkit.Server; //导入依赖的package包/类
public static void setHistoryLength(int length) {
//Cap at 12 History Frames, 1 hour at 5 minute frames.
int maxLength = historyInterval * MAX_HISTORY_FRAMES;
//For special cases of servers with special permission to bypass the max.
//This max helps keep data file sizes reasonable for processing on Aikar's Timing parser side.
//Setting this will not help you bypass the max unless Aikar has added an exception on the API side.
if (Server.getInstance().getConfig().getBoolean("timings.bypass-max", false)) {
maxLength = Integer.MAX_VALUE;
}
historyLength = Math.max(Math.min(maxLength, length), historyInterval);
Queue<TimingsHistory> oldQueue = TimingsManager.HISTORY;
int frames = (getHistoryLength() / getHistoryInterval());
if (length > maxLength) {
Server.getInstance().getLogger().warning(
"Timings Length too high. Requested " + length + ", max is " + maxLength
+ ". To get longer history, you must increase your interval. Set Interval to "
+ Math.ceil(length / MAX_HISTORY_FRAMES)
+ " to achieve this length.");
}
TimingsManager.HISTORY = new TimingsManager.BoundedQueue<>(frames);
TimingsManager.HISTORY.addAll(oldQueue);
}
示例4: complete
import cn.nukkit.Server; //导入依赖的package包/类
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
// buffer could be null
checkNotNull(candidates);
if (buffer == null) {
Server.getInstance().getCommandMap().getCommands().keySet().forEach((cmd) -> candidates.add(cmd));
}
else {
SortedSet<String> names = new TreeSet<String>();
Server.getInstance().getCommandMap().getCommands().keySet().forEach((cmd) -> names.add(cmd));
for (String match : names) {
if (!match.toLowerCase().startsWith(buffer.toLowerCase())) {
continue;
}
candidates.add(match);
}
}
return candidates.isEmpty() ? -1 : 0;
}
示例5: addParticle
import cn.nukkit.Server; //导入依赖的package包/类
public void addParticle(Particle particle, Player[] players) {
DataPacket[] packets = particle.encode();
if (players == null) {
if (packets != null) {
for (DataPacket packet : packets) {
this.addChunkPacket((int) particle.x >> 4, (int) particle.z >> 4, packet);
}
}
} else {
if (packets != null) {
if (packets.length == 1) {
Server.broadcastPacket(players, packets[0]);
} else {
this.server.batchPackets(players, packets, false);
}
}
}
}
示例6: saveResource
import cn.nukkit.Server; //导入依赖的package包/类
@Override
public boolean saveResource(String filename, String outputName, boolean replace) {
Preconditions.checkArgument(filename != null && outputName != null, "Filename can not be null!");
Preconditions.checkArgument(filename.trim().length() != 0 && outputName.trim().length() != 0, "Filename can not be empty!");
File out = new File(dataFolder, outputName);
if (!out.exists() || replace) {
try (InputStream resource = getResource(filename)) {
if (resource != null) {
File outFolder = out.getParentFile();
if (!outFolder.exists()) {
outFolder.mkdirs();
}
Utils.writeFile(out, resource);
return true;
}
} catch (IOException e) {
Server.getInstance().getLogger().logException(e);
}
}
return false;
}
示例7: setHeldItemSlot
import cn.nukkit.Server; //导入依赖的package包/类
public void setHeldItemSlot(int slot) {
if (slot >= -1 && slot < this.getSize()) {
Item item = this.getItem(slot);
int itemIndex = this.getHeldItemIndex();
if (this.getHolder() instanceof Player) {
PlayerItemHeldEvent ev = new PlayerItemHeldEvent((Player) this.getHolder(), item, slot, itemIndex);
Server.getInstance().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
this.sendContents((Player) this.getHolder());
return;
}
}
this.setHotbarSlotIndex(itemIndex, slot);
}
}
示例8: setRaining
import cn.nukkit.Server; //导入依赖的package包/类
public boolean setRaining(boolean raining) {
WeatherChangeEvent ev = new WeatherChangeEvent(this, raining);
this.getServer().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return false;
}
this.raining = raining;
LevelEventPacket pk = new LevelEventPacket();
// These numbers are from Minecraft
if (raining) {
pk.evid = LevelEventPacket.EVENT_START_RAIN;
pk.data = rand.nextInt(50000) + 10000;
setRainTime(rand.nextInt(12000) + 12000);
} else {
pk.evid = LevelEventPacket.EVENT_STOP_RAIN;
setRainTime(rand.nextInt(168000) + 12000);
}
Server.broadcastPacket(this.getPlayers().values(), pk);
return true;
}
示例9: setBlock
import cn.nukkit.Server; //导入依赖的package包/类
@Override
public boolean setBlock(int x, int y, int z, Integer blockId, Integer meta) {
int id = blockId == null ? 0 : blockId;
int damage = meta == null ? 0 : meta;
try {
this.hasChanged = true;
return this.sections[y >> 4].setBlock(x, y & 0x0f, z, id, damage);
} catch (ChunkException e) {
int Y = y >> 4;
try {
this.setInternalSection(Y, (ChunkSection) this.providerClass.getMethod("createChunkSection", int.class).invoke(this.providerClass, Y));
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e1) {
Server.getInstance().getLogger().logException(e1);
}
return this.sections[y >> 4].setBlock(x, y & 0x0f, z, id, damage);
}
}
示例10: addLevelSoundEvent
import cn.nukkit.Server; //导入依赖的package包/类
public void addLevelSoundEvent(byte type, int pitch, int data, Vector3 pos, Collection<Player> players, boolean unknown, boolean disableRelativeVolume) {
LevelSoundEventPacket pk = new LevelSoundEventPacket();
pk.sound = type;
pk.pitch = pitch;
pk.extraData = data;
pk.x = (float) pos.x;
pk.y = (float) pos.y;
pk.z = (float) pos.z;
pk.unknownBool = unknown;
pk.disableRelativeVolume = disableRelativeVolume;
if (players == null) {
this.addChunkPacket(pos.getFloorX(), pos.getFloorZ(), pk);
} else {
Server.broadcastPacket(players, pk);
}
}
示例11: onActivate
import cn.nukkit.Server; //导入依赖的package包/类
@Override
public boolean onActivate(Item item, Player player) {
if (item.getId() == Item.DYE && item.getDamage() == 0x0f) {
Block block = this.clone();
if (this.meta / 4 < 2) {
block.meta += 4;
BlockGrowEvent ev = new BlockGrowEvent(this, block);
Server.getInstance().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return false;
}
this.getLevel().setBlock(this, ev.getNewState(), true, true);
}
this.level.addParticle(new BoneMealParticle(this.add(0.5, 0.5, 0.5)));
item.count--;
return true;
}
return false;
}
示例12: RCON
import cn.nukkit.Server; //导入依赖的package包/类
public RCON(Server server, String password, String address, int port) {
if (password.isEmpty()) {
server.getLogger().critical(server.getLanguage().translateString("nukkit.server.rcon.emptyPasswordError"));
return;
}
this.server = server;
try {
this.serverThread = new RCONServer(address, port, password);
this.serverThread.start();
} catch (IOException exception) {
this.server.getLogger().critical(this.server.getLanguage().translateString("nukkit.server.rcon.startupError", exception.getMessage()));
return;
}
this.server.getLogger().info(this.server.getLanguage().translateString("nukkit.server.rcon.running", new String[]{address, String.valueOf(port)}));
}
示例13: setLevel
import cn.nukkit.Server; //导入依赖的package包/类
/**
* Levelを変更します
* @param levelName
* @return boolean
*/
public boolean setLevel(String levelName) {
Level level = Server.getInstance().getLevelByName(levelName);
if (level != null) {
sendToLevel(SEND_TYPE_REMOVE);
Level tmpLevel = this.level;
this.level = level;
if (api.saveFt(this, false)) {
sendToLevel(SEND_TYPE_ADD);
return true;
}else {
this.level = tmpLevel;
sendToLevel(SEND_TYPE_ADD);
}
}
return false;
}
示例14: QueryRegenerateEvent
import cn.nukkit.Server; //导入依赖的package包/类
public QueryRegenerateEvent(Server server, int timeout) {
this.timeout = timeout;
this.serverName = server.getMotd();
this.listPlugins = (boolean) server.getConfig("settings.query-plugins", true);
this.plugins = server.getPluginManager().getPlugins().values().toArray(new Plugin[server.getPluginManager().getPlugins().values().size()]);
List<Player> players = new ArrayList<>();
for (Player player : server.getOnlinePlayers().values()) {
if (player.isOnline()) {
players.add(player);
}
}
this.players = players.toArray(new Player[players.size()]);
this.gameType = (server.getGamemode() & 0x01) == 0 ? "SMP" : "CMP";
this.version = server.getVersion();
this.server_engine = server.getName() + " " + server.getNukkitVersion();
this.map = server.getDefaultLevel() == null ? "unknown" : server.getDefaultLevel().getName();
this.numPlayers = this.players.length;
this.maxPlayers = server.getMaxPlayers();
this.whitelist = server.hasWhitelist() ? "on" : "off";
this.port = server.getPort();
this.ip = server.getIp();
}
示例15: run
import cn.nukkit.Server; //导入依赖的package包/类
public void run(){
while (true){
try{
for (Player player : Server.getInstance().getOnlinePlayers().values()){
if (positionHashMap.containsKey(player.getName())){
Position from = positionHashMap.get(player.getName());
Position to = player.getPosition();
float move = ((float) Math.sqrt(Math.pow(from.x - to.x,2)+Math.pow(from.z - to.z,2)));
putMove(player.getName(),move);
positionHashMap.put(player.getName(),player.getPosition());
} else {
putMove(player.getName(),0F);
positionHashMap.put(player.getName(),player.getPosition());
}
}
thread.sleep(50);
}catch (Exception e){
e.printStackTrace();
}
}
}