本文整理汇总了Java中org.spongepowered.api.world.Location类的典型用法代码示例。如果您正苦于以下问题:Java Location类的具体用法?Java Location怎么用?Java Location使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Location类属于org.spongepowered.api.world包,在下文中一共展示了Location类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tryCreateHologram
import org.spongepowered.api.world.Location; //导入依赖的package包/类
public static Optional<HologramsService.Hologram> tryCreateHologram(Location<World> location, Optional<Text> optional_text) {
if (!optional_text.isPresent()) {
return Optional.empty();
}
Text text = optional_text.get();
Optional<HologramsService> optional_hologram_service = GWMCrates.getInstance().getHologramsService();
if (!optional_hologram_service.isPresent()) {
GWMCrates.getInstance().getLogger().warn("Unable to create hologram, Holograms Service not found!");
return Optional.empty();
}
HologramsService holograms_service = optional_hologram_service.get();
location.getExtent().loadChunk(location.getChunkPosition(), true);
Optional<HologramsService.Hologram> optional_hologram = holograms_service.
createHologram(location.add(GWMCrates.getInstance().getHologramOffset()), text);
if (!optional_hologram.isPresent()) {
GWMCrates.getInstance().getLogger().warn("Holograms Service found, but hologram can not be created! :-(");
return Optional.empty();
}
return optional_hologram;
}
示例2: adminCoordsCommand
import org.spongepowered.api.world.Location; //导入依赖的package包/类
@Command(name = "coords", description = "See the coordinates of a clan's members", spongePermission = "mcclans.admin.coords")
public void adminCoordsCommand(CommandSource commandSource, @Parameter(name = "clanTag") ClanImpl clan, @PageParameter int page) {
List<Player> onlineMembers = new ArrayList<Player>();
List<ClanPlayerImpl> members = clan.getMembersImpl();
for (ClanPlayerImpl member : members) {
Optional<Player> playerOpt = Sponge.getServer().getPlayer(member.getUUID());
if (playerOpt.isPresent() && playerOpt.get().isOnline()) {
onlineMembers.add(playerOpt.get());
}
}
java.util.Collections.sort(members, new MemberComparator());
HorizontalTable<Player> table = new HorizontalTable<>("Clan coordinates " + clan.getName(), 10, (TableAdapter<Player>) (row, player, index) -> {
if (player.isOnline()) {
Location<World> location = player.getLocation();
row.setValue("Player", Text.of(player.getName()));
row.setValue("Location", Utils.formatLocation(location));
}
});
table.defineColumn("Player", 30);
table.defineColumn("Location", 30);
table.draw(onlineMembers, page, commandSource);
}
示例3: clanCoordsCommand
import org.spongepowered.api.world.Location; //导入依赖的package包/类
@Command(name = "coords", description = "Посмотреть координаты ваших соклановцев", isPlayerOnly = true, isClanOnly = true, clanPermission = "coords", spongePermission = "mcclans.user.coords")
public void clanCoordsCommand(CommandSource commandSource, ClanPlayerImpl clanPlayer, @PageParameter int page) {
ClanImpl clan = clanPlayer.getClan();
List<Player> onlineMembers = new ArrayList<Player>();
List<ClanPlayerImpl> members = clan.getMembersImpl();
for (ClanPlayerImpl member : members) {
Optional<Player> playerOpt = Sponge.getServer().getPlayer(member.getUUID());
if (playerOpt.isPresent() && playerOpt.get().isOnline()) {
onlineMembers.add(playerOpt.get());
}
}
java.util.Collections.sort(members, new MemberComparator());
HorizontalTable<Player> table = new HorizontalTable<Player>("Clan coordinates " + clan.getName(), 10, (row, player, index) -> {
if (player.isOnline()) {
Location<World> location = player.getLocation();
row.setValue("Player", Text.of(player.getName()));
row.setValue("Location", Utils.formatLocation(location));
}
});
table.defineColumn("Player", 30);
table.defineColumn("Location", 30);
table.draw(onlineMembers, page, commandSource);
}
示例4: loadedClan
import org.spongepowered.api.world.Location; //导入依赖的package包/类
protected void loadedClan(int clanID, String clanTag, String clanName, int ownerID, String tagColorId, boolean allowAllyInvites,
boolean ffProtection, long creationTime, String homeWorld, double homeX, double homeY, double homeZ, float homeYaw, float homePitch,
int homeSetTimes, long homeLastSetTimeStamp, String bankId) {
ClanImpl clan = new ClanImpl.Builder(clanID, clanTag, clanName).tagColor(Utils.getTextColorById(tagColorId, Config.getColor(Config.CLAN_TAG_DEFAULT_COLOR))).acceptAllyInvites(allowAllyInvites)
.ffProtection(ffProtection).creationTime(creationTime).homeSetTimes(homeSetTimes).homeLastSetTimeStamp(homeLastSetTimeStamp).bankId(bankId).build();
if (homeWorld != null && Sponge.getServer().getWorld(UUID.fromString(homeWorld)).isPresent()) {
// TODO SPONGE homeYaw, homePitch
clan.setHomeInternal(new Location<>(Sponge.getServer().getWorld(UUID.fromString(homeWorld)).get(), homeX, homeY, homeZ));
}
clan.addRank(RankFactory.getInstance().createOwner());
clan.addRank(RankFactory.getInstance().createRecruit());
clanOwners.put(clanID, ownerID);
clans.put(clanID, clan);
checkHighestUsedClanID(clanID);
}
示例5: SignsConfig
import org.spongepowered.api.world.Location; //导入依赖的package包/类
public SignsConfig(File baseDir) {
super(baseDir, "signs");
for (Object objKey : config.getChildrenMap().keySet()) {
if (objKey instanceof String) {
String key = (String) objKey;
if (Utils.isInt(key)) {
Set<DonorSign> signs = new HashSet<>();
System.out.println("key " + key);
try {
for (Location<World> loc : stringsToLocArray(config.getChildrenMap().get(objKey).getList(TypeToken.of(String.class)))) {
if (loc != null && loc.getTileEntity().isPresent() && loc.getTileEntity().get() instanceof Sign) {
System.out.println("2");
signs.add(new DonorSign(Utils.getInt(key), loc));
}
}
} catch (ObjectMappingException e) {
e.printStackTrace();
}
donorSigns.put(Utils.getInt(key), signs);
}
}
}
}
示例6: addDonorSign
import org.spongepowered.api.world.Location; //导入依赖的package包/类
public boolean addDonorSign(Integer key, Location<World> location) {
DonorSign donorSign = getDonorSignFor(location);
if (donorSign == null) {
Set<DonorSign> signs;
if (donorSigns.containsKey(key)) {
signs = donorSigns.get(key);
} else {
signs = new HashSet<>();
}
signs.add(new DonorSign(key, location));
donorSigns.put(key, signs);
List<String> locs = new ArrayList<>();
for (DonorSign ds : signs) {
locs.add(locToString(ds.getLocation()));
}
if (locs.size() > 0) {
config.getNode(String.valueOf(key)).setValue(locs);
} else {
config.getNode(String.valueOf(key)).setValue(null);
}
saveConfig();
return true;
}
return false;
}
示例7: removeDonorSign
import org.spongepowered.api.world.Location; //导入依赖的package包/类
public boolean removeDonorSign(Location<World> location) {
DonorSign donorSign = getDonorSignFor(location);
if (donorSign != null) {
Set<DonorSign> signs = donorSigns.get(donorSign.getKey());
signs.remove(donorSign);
List<String> locs = new ArrayList<>();
for (DonorSign ds : signs) {
locs.add(locToString(ds.getLocation()));
}
if (locs.size() > 0) {
config.getNode(String.valueOf(donorSign.getKey())).setValue(locs);
} else {
config.getNode(String.valueOf(donorSign.getKey())).setValue(null);
}
saveConfig();
return true;
}
return false;
}
示例8: stringToLoc
import org.spongepowered.api.world.Location; //导入依赖的package包/类
private Location<World> stringToLoc(String str) {
String[] a = str.split(",");
if (a.length < 4) {
return null;
}
Optional<World> w = Sponge.getServer().getWorld(a[0]);
if (!w.isPresent()) {
return null;
}
double x = Double.parseDouble(a[1]);
double y = Double.parseDouble(a[2]);
double z = Double.parseDouble(a[3]);
return new Location<>(w.get(), x, y, z);
}
示例9: onChangeBlockEvent
import org.spongepowered.api.world.Location; //导入依赖的package包/类
@Listener
public void onChangeBlockEvent(ChangeBlockEvent.Break e, @First Player player) {
if (plugin.getMainConfig().isUseSigns()) {
if (player.hasPermission("minecraftmarket.signs")) {
if (e.getTransactions().size() > 0) {
BlockSnapshot blockSnapshot = e.getTransactions().get(0).getOriginal();
Optional<Location<World>> optionalLocation = blockSnapshot.getLocation();
if (optionalLocation.isPresent()) {
if (plugin.getSignsConfig().getDonorSignFor(optionalLocation.get()) != null) {
if (plugin.getSignsConfig().removeDonorSign(optionalLocation.get())) {
player.sendMessage(Colors.color(I18n.tl("prefix") + " " + I18n.tl("sign_removed")));
plugin.getSignsTask().updateSigns();
}
}
}
}
}
}
}
示例10: deserialize
import org.spongepowered.api.world.Location; //导入依赖的package包/类
@Override
public Location deserialize(TypeToken<?> typeToken, ConfigurationNode value) throws ObjectMappingException {
String name = value.getNode("world").getValue(TypeToken.of(String.class));
Double x = value.getNode("x").getValue(TypeToken.of(Double.class));
Double y = value.getNode("y").getValue(TypeToken.of(Double.class));
Double z = value.getNode("z").getValue(TypeToken.of(Double.class));
Optional<World> optional = Sponge.getServer().getWorld(name);
if (!optional.isPresent()) {
throw new ObjectMappingException("Unknown world");
}
World world = optional.get();
return world.getLocation(x, y, z);
}
示例11: loadCameras
import org.spongepowered.api.world.Location; //导入依赖的package包/类
/**
* loads the cameras from the config
*
* may only be called after the worlds of the server have been loaded
*/
public void loadCameras() {
plugin.getCameras().clear();
// yes i know it is bad to register it every time the config is loaded but i doesn't seem to work otherwise...
TypeSerializers.getDefaultSerializers().registerType(TypeToken.of(Location.class), new LocationSerializer());
config.getNode("cameras").getChildrenList().forEach((node) -> {
try {
Camera cam = node.getValue(TypeToken.of(Camera.class));
cam.setLocation(node.getNode("location").getValue(TypeToken.of(Location.class)));
plugin.getCameras().put(cam.getId(), cam);
} catch (ObjectMappingException e) {
System.out.println(TypeSerializers.getDefaultSerializers().get(TypeToken.of(Location.class)));
logger.warn("Couldn't load Camera: " + e.getMessage());
}
});
logger.info(String.format("Loaded %d Cameras", plugin.getCameras().size()));
}
示例12: onLiquidFlow
import org.spongepowered.api.world.Location; //导入依赖的package包/类
@Listener(order = Order.POST)
public void onLiquidFlow(ChangeBlockEvent.Pre e) {
if (e.getLocations().isEmpty()) return;
Location<World> loc = e.getLocations().get(0);
BlockSnapshot snapshot = loc.getExtent().createSnapshot(loc.getBlockPosition());
Optional<MatterProperty> matter = snapshot.getState().getProperty(MatterProperty.class);
if (matter.isPresent() && matter.get().getValue() == Matter.LIQUID) {
String name = "Water";
BlockType type = snapshot.getState().getType();
if (type == BlockTypes.LAVA || type == BlockTypes.FLOWING_LAVA)
name = "Lava";
db.addToQueue(new BlockQueueEntry(snapshot, ActionType.FLOW, name, new Date().getTime()));
}
}
示例13: onBlockPrimaryInteract
import org.spongepowered.api.world.Location; //导入依赖的package包/类
@Listener
public void onBlockPrimaryInteract(InteractBlockEvent.Primary.MainHand e, @First Player p) {
if (!plugin.getInspectManager().isInspector(p))
return;
e.setCancelled(true);
BlockSnapshot block = e.getTargetBlock();
if (block == null || !block.getLocation().isPresent())
return;
Location<World> loc = block.getLocation().get();
p.sendMessage(Text.of(TextColors.BLUE, "Querying database, please wait..."));
Sponge.getScheduler().createAsyncExecutor(plugin).execute(() -> {
plugin.getInspectManager().inspect(p, block.getWorldUniqueId(), loc.getBlockPosition()); });
}
示例14: onBlockSecondaryInteract
import org.spongepowered.api.world.Location; //导入依赖的package包/类
@Listener
public void onBlockSecondaryInteract(InteractBlockEvent.Secondary.MainHand e, @First Player p) {
if (!plugin.getInspectManager().isInspector(p))
return;
//TODO: Figure out why shearing sheep causes weird shit to happen
e.setCancelled(true);
BlockSnapshot block = e.getTargetBlock();
if (block == null || !block.getLocation().isPresent())
return;
Location<World> loc = block.getLocation().get();
p.sendMessage(Text.of(TextColors.BLUE, "Querying database, please wait..."));
if (loc.getTileEntity().isPresent() && loc.getTileEntity().get() instanceof TileEntityCarrier) {
Sponge.getScheduler().createAsyncExecutor(plugin).execute(() -> {
plugin.getInspectManager().inspectContainer(p, block.getWorldUniqueId(), loc.getBlockPosition()); });
} else {
Sponge.getScheduler().createAsyncExecutor(plugin).execute(() -> {
plugin.getInspectManager().inspect(p, block.getWorldUniqueId(), loc.getBlockPosition().add(e.getTargetSide().asBlockOffset())); });
}
}
示例15: handle
import org.spongepowered.api.world.Location; //导入依赖的package包/类
@Override
public void handle(Player player, Location<World> location) {
try {
if (Keys.getStorageAdapter().getLocks(location).isEmpty()) {
player.sendMessage(Format.error("This block isn't locked."));
} else {
if (player.hasPermission("keys.mod") || Keys.getStorageAdapter().ownsLock(player, location)) {
Keys.getStorageAdapter().removeLock(recipient, location);
player.sendMessage(Format.success(String.format("Destroyed key for %s", recipient.getName())));
// Add a key to partner
Optional<Location<World>> partner = WorldUtil.findPartnerBlock(location);
if (partner.isPresent()) {
player.sendMessage(Text.of(TextColors.GRAY, "Keying partner location too..."));
Keys.getStorageAdapter().removeLock(recipient, partner.get());
}
} else {
player.sendMessage(Format.error("Cannot unlock, you do not own this lock."));
}
}
} catch(SQLException e) {
player.sendMessage(Format.error("Storage error. Details have been logged."));
}
}