本文整理汇总了Java中org.bukkit.WorldBorder类的典型用法代码示例。如果您正苦于以下问题:Java WorldBorder类的具体用法?Java WorldBorder怎么用?Java WorldBorder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WorldBorder类属于org.bukkit包,在下文中一共展示了WorldBorder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onEnable
import org.bukkit.WorldBorder; //导入依赖的package包/类
public void onEnable() {
registerListeners();
registerCommands();
ConfigManager.getInstance().setup(this);
WorldBorder b = Bukkit.getWorld("world").getWorldBorder();
b.setCenter(new Location(Bukkit.getWorld("world"), 0, 64, 0));
b.setSize(SettingsManager.border);
BukkitScheduler scheduler = getServer().getScheduler();
scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
@Override
public void run() {
Bukkit.broadcastMessage("loop all players: :kappa:");
if(GameManager.getGameSituation()) {
if(GameManager.getStartTime() + 600000 > System.currentTimeMillis()) {
b.setSize(b.getSize() - 1);
}
}
}
}, 0L, 1 * 20L);
}
示例2: testWorldBorder
import org.bukkit.WorldBorder; //导入依赖的package包/类
@Test
public void testWorldBorder() {
int size = 500;
int damageAmt = 5;
Location loc = TestLocation.LOC_ZERO;
WorldBorder border = new TestWorldBorder(size, damageAmt, loc);
String out = OutputFormatter.getOutput(border);
assertNotNull(out);
assertTrue(out.contains(String.valueOf(size)));
assertTrue(out.contains(String.valueOf(damageAmt)));
assertTrue(out.contains(String.valueOf(loc.getBlockZ())));
assertTrue(out.contains(String.valueOf(loc.getBlockY())));
assertTrue(out.contains(String.valueOf(loc.getBlockZ())));
}
示例3: isInsideBorder
import org.bukkit.WorldBorder; //导入依赖的package包/类
/**
* Checks if the given location is inside the world border of his world.
*
* @param location The location.
*
* @return The result of the check.
*/
public static boolean isInsideBorder(Location location)
{
World world = location.getWorld();
WorldBorder border = world.getWorldBorder();
Double borderRadius = border.getSize() / 2;
Double xMin = border.getCenter().getX() - borderRadius;
Double xMax = border.getCenter().getX() + borderRadius;
Double zMin = border.getCenter().getZ() - borderRadius;
Double zMax = border.getCenter().getZ() + borderRadius;
Double x = location.getX();
Double z = location.getZ();
return (x > xMin && x < xMax) && (z > zMin && z < zMax);
}
示例4: BorderManagement
import org.bukkit.WorldBorder; //导入依赖的package包/类
public BorderManagement(int size, int decreaseSize, Location loc, int triggerTime){
if(size<1 && decreaseSize>size){
System.out.println("Wielkosc granicy musi byc >1");
this.size = 1000;
this.loc = loc;
this.decreasedSize = 100;
this.triggerTime = 60;
}else{
this.size = size;
this.loc = loc;
this.decreasedSize = decreaseSize;
this.triggerTime = triggerTime;
}
WorldBorder wb = loc.getWorld().getWorldBorder();
wb.setCenter(loc);
wb.setDamageAmount(2);
wb.setWarningTime(5);
wb.setSize(size);
wb.setWarningDistance(30);
}
示例5: canCast
import org.bukkit.WorldBorder; //导入依赖的package包/类
public boolean canCast(Location location) {
if (location == null) return true;
if (!hasCastPermission(mage.getCommandSender())) return false;
Entity entity = mage.getEntity();
if (disguiseRestricted && entity != null && entity instanceof Player && controller.isDisguised(entity)) return false;
Boolean regionPermission = controller.getRegionCastPermission(mage.getPlayer(), this, location);
if (regionPermission != null && regionPermission == true) return true;
Boolean personalPermission = controller.getPersonalCastPermission(mage.getPlayer(), this, location);
if (personalPermission != null && personalPermission == true) return true;
if (regionPermission != null && regionPermission == false) return false;
if (requiresBuildPermission() && !hasBuildPermission(location.getBlock())) return false;
if (requiresBreakPermission() && !hasBreakPermission(location.getBlock())) return false;
if (worldBorderRestricted)
{
WorldBorder border = location.getWorld().getWorldBorder();
double borderSize = border.getSize() / 2 - border.getWarningDistance();
Location offset = location.subtract(border.getCenter());
if (offset.getX() < -borderSize || offset.getX() > borderSize || offset.getZ() < -borderSize || offset.getZ() > borderSize) return false;
}
return !pvpRestricted || bypassPvpRestriction || mage.isPVPAllowed(location);
}
示例6: resetWorldBorder
import org.bukkit.WorldBorder; //导入依赖的package包/类
public void resetWorldBorder(Player player) {
try {
WorldBorder originalWorldBorder = player.getWorld().getWorldBorder();
Constructor packetWorldBorderConstructor = NMSUtil.getNmsClass("PacketPlayOutWorldBorder").getConstructor(NMSUtil.getNmsClass("WorldBorder"), NMSUtil.getNmsClass("PacketPlayOutWorldBorder$EnumWorldBorderAction"));
Object worldBorder = NMSUtil.getNmsClass("WorldBorder").getConstructor().newInstance();
worldBorder.getClass().getMethod("setCenter", double.class, double.class).invoke(worldBorder, originalWorldBorder.getCenter().getX(), originalWorldBorder.getCenter().getZ());
worldBorder.getClass().getMethod("setSize", double.class).invoke(worldBorder, originalWorldBorder.getSize());
worldBorder.getClass().getMethod("setDamageBuffer", double.class).invoke(worldBorder, originalWorldBorder.getDamageBuffer());
worldBorder.getClass().getMethod("setDamageAmount", double.class).invoke(worldBorder, originalWorldBorder.getDamageAmount());
worldBorder.getClass().getMethod("setWarningDistance", int.class).invoke(worldBorder, originalWorldBorder.getWarningDistance());
worldBorder.getClass().getMethod("setWarningTime", int.class).invoke(worldBorder, originalWorldBorder.getWarningTime());
Object[] enums = NMSUtil.getNmsClass("PacketPlayOutWorldBorder$EnumWorldBorderAction").getEnumConstants();
Object packet = packetWorldBorderConstructor.newInstance(worldBorder, enums[3]);
NMSUtil.sendPacket(player, packet);
} catch (ClassNotFoundException | NoSuchMethodException | NoSuchFieldException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
}
示例7: resetWorldBorder
import org.bukkit.WorldBorder; //导入依赖的package包/类
@Override
public void resetWorldBorder(Player player) {
try {
WorldBorder originalWorldBorder = player.getWorld().getWorldBorder();
Constructor packetWorldBorderConstructor = NMSUtil.getNmsClass("PacketPlayOutWorldBorder").getConstructor(NMSUtil.getNmsClass("WorldBorder"), NMSUtil.getNmsClass("PacketPlayOutWorldBorder$EnumWorldBorderAction"));
Object worldBorder = NMSUtil.getNmsClass("WorldBorder").getConstructor().newInstance();
worldBorder.getClass().getMethod("setCenter", double.class, double.class).invoke(worldBorder, originalWorldBorder.getCenter().getX(), originalWorldBorder.getCenter().getZ());
worldBorder.getClass().getMethod("setSize", double.class).invoke(worldBorder, originalWorldBorder.getSize());
worldBorder.getClass().getMethod("setDamageBuffer", double.class).invoke(worldBorder, originalWorldBorder.getDamageBuffer());
worldBorder.getClass().getMethod("setDamageAmount", double.class).invoke(worldBorder, originalWorldBorder.getDamageAmount());
worldBorder.getClass().getMethod("setWarningDistance", int.class).invoke(worldBorder, originalWorldBorder.getWarningDistance());
worldBorder.getClass().getMethod("setWarningTime", int.class).invoke(worldBorder, originalWorldBorder.getWarningTime());
Object[] enums = NMSUtil.getNmsClass("PacketPlayOutWorldBorder$EnumWorldBorderAction").getEnumConstants();
Object packet = packetWorldBorderConstructor.newInstance(worldBorder, enums[3]);
NMSUtil.sendPacket(player, packet);
} catch (ClassNotFoundException | NoSuchMethodException | NoSuchFieldException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
}
示例8: run
import org.bukkit.WorldBorder; //导入依赖的package包/类
@Override
public void run() {
plugin.getServer().getOnlinePlayers().forEach(p ->
Lang.sendMessage(p, "messages.game.shrinking")
);
times--;
WorldBorder wb = battles.getWorld().getWorldBorder();
double newSize = wb.getSize() - amount;
if(newSize > 0) {
wb.setSize(newSize, shrinkTime);
}
if(times <= 0) cancel();
}
示例9: onWorldLoad
import org.bukkit.WorldBorder; //导入依赖的package包/类
@EventHandler
private void onWorldLoad(WorldLoadEvent e){
e.getWorld().setAutoSave(false);
WorldBorder b = e.getWorld().getWorldBorder();
b.setCenter(0d, 0d);
b.setSize(3000000d);
plugin.getLogger().info(String.format("Auto-save for world [" + e.getWorld().getName() + "] is prevented! "));
}
示例10: isInsideBorder
import org.bukkit.WorldBorder; //导入依赖的package包/类
public static boolean isInsideBorder(Location location) {
WorldBorder border = location.getWorld().getWorldBorder();
Location center = border.getCenter();
double radius = border.getSize() / 2d;
return Math.abs(location.getX() - center.getX()) < radius &&
Math.abs(location.getZ() - center.getZ()) < radius;
}
示例11: clampToBorder
import org.bukkit.WorldBorder; //导入依赖的package包/类
public static boolean clampToBorder(Location location) {
WorldBorder border = location.getWorld().getWorldBorder();
Location center = border.getCenter();
double radius = border.getSize() / 2d;
double xMin = center.getX() - radius;
double xMax = center.getX() + radius;
double zMin = center.getZ() - radius;
double zMax = center.getZ() + radius;
boolean moved = false;
if(location.getX() < xMin) {
location.setX(xMin);
moved = true;
}
if(location.getX() > xMax) {
location.setX(xMax);
moved = true;
}
if(location.getZ() < zMin) {
location.setZ(zMin);
moved = true;
}
if(location.getZ() > zMax) {
location.setZ(zMax);
moved = true;
}
return moved;
}
示例12: getOutput
import org.bukkit.WorldBorder; //导入依赖的package包/类
@Nullable
public static String getOutput(@Nullable Object object) {
if (object == null) {
return null;
}
if (object instanceof String) {
return (String) object;
} else if (object instanceof Collection) {
return handleCollection((Collection) object);
} else if (object instanceof Map) {
return handleMap((Map) object);
} else if (object.getClass().isArray()) {
return handleArray(object);
} else if (object instanceof OfflinePlayer) {
return handleOfflinePlayer((OfflinePlayer) object);
} else if (object instanceof BlockState) {
return handleBlockState((BlockState) object);
} else if (object instanceof Inventory) {
return handleInventory((Inventory) object);
} else if (object instanceof WorldBorder) {
return handleWorldBorder((WorldBorder) object);
} else if (object instanceof CommandSender) {
return handleCommandSender((CommandSender) object);
} else if (object instanceof Messenger) {
return handleMessenger((Messenger) object);
} else if (object instanceof HelpMap) {
return handleHelpMap((HelpMap) object);
} else {
return String.valueOf(object);
}
}
示例13: execute
import org.bukkit.WorldBorder; //导入依赖的package包/类
@Override
protected void execute(Event event) {
World world = worldExpression.getSingle(event);
WorldBorder border = world.getWorldBorder();
double value = numberExpression.getSingle(event).doubleValue();
long seconds = timespanExpression.getSingle(event).getMilliSeconds() / 1000;
switch (changeMode) {
case SET: border.setSize(value, seconds); break;
case ADD: border.setSize(border.getSize() + value, seconds); break;
case REMOVE: border.setSize(border.getSize() - value, seconds); break;
}
}
示例14: getBorderReplacement
import org.bukkit.WorldBorder; //导入依赖的package包/类
private static WorldBorder getBorderReplacement(World world) {
if (BORDER_REPLACER == null) {
if (Reflection.methodExists(WorldBorder.class, "isInside", Location.class)) {
BORDER_REPLACER = WorldBorderImplExt::new;
} else {
BORDER_REPLACER = WorldBorderImpl::new;
}
}
return BORDER_REPLACER.apply(world);
}
示例15: getProperty
import org.bukkit.WorldBorder; //导入依赖的package包/类
public static Number getProperty(WorldBorder border, BorderProperty borderProperty) {
switch (borderProperty) {
case DIAMETER: return border.getSize();
case DAMAGE_AMOUNT: return border.getDamageAmount();
case DAMAGE_BUFFER: return border.getDamageBuffer();
case WARNING_DISTANCE: return border.getWarningDistance();
case WARNING_TIME: return border.getWarningTime();
}
throw new IllegalArgumentException("Illegal BorderProperty: " + borderProperty);
}