use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class MarketUntrackItemComand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command!"));
return CommandResult.empty();
}
Optional<MarketService> optService = Sponge.getServiceManager().provide(MarketService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The market service is not currently running."));
return CommandResult.empty();
}
MarketService service = optService.get();
Optional<ItemStack> held = ((Player) src).getItemInHand(HandTypes.MAIN_HAND);
if (!held.isPresent()) {
src.sendMessage(Text.of(TextColors.RED, "You are not holding an item."));
return CommandResult.empty();
}
ItemStack item = held.get();
if (service.remItem(item)) {
src.sendMessage(Text.of(TextColors.YELLOW, "Your held item is no longer being tracked."));
} else {
src.sendMessage(Text.of(TextColors.RED, "Your held item is not tracked."));
return CommandResult.empty();
}
return CommandResult.success();
}
use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class ZoneMasterOrb method onBlockInteract.
@Listener
public void onBlockInteract(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<org.spongepowered.api.item.inventory.ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optItemStack.isPresent()) {
return;
}
ItemStack itemStack = tf(optItemStack.get());
if (!isZoneMasterItem(itemStack)) {
return;
}
if (isAttuned(itemStack)) {
if (isInInstanceWorld(player)) {
player.sendMessage(Text.of(TextColors.RED, "You cannot start an instance from within an instance."));
event.setCancelled(true);
return;
}
Optional<ZoneService> optService = Sponge.getServiceManager().provide(ZoneService.class);
if (optService.isPresent()) {
Task.builder().execute(() -> {
ZoneService service = optService.get();
List<Player> group = new ArrayList<>();
group.add(player);
for (Player aPlayer : Sponge.getServer().getOnlinePlayers()) {
ItemStack[] itemStacks = tf(aPlayer).inventory.mainInventory;
for (ItemStack aStack : itemStacks) {
if (!hasSameZoneID(itemStack, aStack)) {
continue;
}
if (isAttuned(aStack) && isZoneSlaveItem(aStack)) {
Optional<Player> optZoneOwner = getGroupOwner(aStack);
if (optZoneOwner.isPresent()) {
group.add(aPlayer);
break;
}
}
}
}
for (int i = group.size() - 1; i >= 0; --i) {
purgeZoneItems(group.get(i), itemStack);
// createLightningStrike(group.get(i)); SpongeCommon/420
saveLocation(group.get(i));
getMainWorldWrapper().getLobby().add(group.get(i));
}
service.requestZone(getZone(itemStack).get(), group, () -> {
getMainWorldWrapper().getLobby().remove(group);
}, result -> {
if (result.isPresent()) {
result.get().stream().filter(entry -> entry.getValue() != ZoneStatus.ADDED).forEach(entry -> {
player.setLocation(getRespawnLocation(player));
player.sendMessage(Text.of(TextColors.RED, "You could not be added to the zone."));
});
}
});
}).delayTicks(1).submit(SkreePlugin.inst());
}
}
event.setUseBlockResult(Tristate.FALSE);
}
use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class PactScroll method onEntityInteract.
@Listener
public void onEntityInteract(InteractEntityEvent.Primary event, @Root Player player) {
Entity targetEntity = event.getTargetEntity();
if (!(targetEntity instanceof Player)) {
return;
}
Player targetPlayer = (Player) targetEntity;
Optional<ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optItemStack.isPresent()) {
return;
}
ItemStack itemStack = optItemStack.get();
if (itemStack.getItem() != this) {
return;
}
pactMap.putIfAbsent(player.getUniqueId(), new ArrayList<>());
List<UUID> pacts = pactMap.get(player.getUniqueId());
if (pacts.contains(targetPlayer.getUniqueId())) {
pacts.remove(targetPlayer.getUniqueId());
player.sendMessage(Text.of(TextColors.YELLOW, "Your pact with ", targetPlayer.getName(), " has been broken!"));
} else {
pacts.add(targetPlayer.getUniqueId());
player.sendMessage(Text.of(TextColors.YELLOW, "You've formed a pact with ", targetPlayer.getName(), "."));
player.sendMessage(Text.of(TextColors.YELLOW, "You will no longer be able to damage ", targetPlayer.getName(), ", unless attacked first."));
player.sendMessage(Text.of(TextColors.YELLOW, "You must carry a pact scroll for the pact to remain in effect."));
player.sendMessage(Text.of(TextColors.YELLOW, "All pacts will automatically be reset upon disconnect."));
}
event.setCancelled(true);
}
use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class PactScroll method onBlockInteract.
@Listener
public void onBlockInteract(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
Optional<ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optItemStack.isPresent()) {
return;
}
ItemStack itemStack = optItemStack.get();
if (itemStack.getItem() != this) {
return;
}
UserStorageService userService = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
List<Text> result = pactMap.getOrDefault(player.getUniqueId(), new ArrayList<>()).stream().map(userService::get).filter(Optional::isPresent).map(Optional::get).sorted((a, b) -> a.getName().compareToIgnoreCase(b.getName())).map(a -> Text.of((a.isOnline() ? TextColors.GREEN : TextColors.RED), a.getName())).collect(Collectors.toList());
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Pact Members")).padding(Text.of(" ")).sendTo(player);
event.setUseBlockResult(Tristate.FALSE);
}
use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class ZoneItemUtil method purgeZoneItems.
public static void purgeZoneItems(EntityPlayer player, @Nullable ItemStack activating) {
ItemStack[] itemStacks = player.inventory.mainInventory;
for (int i = 0; i < itemStacks.length; ++i) {
if (isZoneItem(itemStacks[i])) {
if (isZoneMasterItem(itemStacks[i])) {
// Check to see if this is the activating item, if so remove it
if (activating != null && hasSameZoneID(itemStacks[i], activating)) {
itemStacks[i] = null;
continue;
}
// Close groups for master orbs carried by other players
if (isAttuned(itemStacks[i])) {
rescindGroupInvite(itemStacks[i]);
ItemStack reset = new ItemStack(CustomItemTypes.ZONE_MASTER_ORB);
setMasterToZone(reset, getZone(itemStacks[i]).get());
itemStacks[i] = reset;
}
continue;
} else if (isZoneSlaveItem(itemStacks[i])) {
if (activating == null || !hasSameZoneID(itemStacks[i], activating)) {
notifyGroupOwner(itemStacks[i], (Player) player, false);
}
}
itemStacks[i] = null;
}
}
player.inventoryContainer.detectAndSendChanges();
}
Aggregations