use of org.apache.commons.lang3.tuple.Triple in project ImmersiveEngineering by BluSunrize.
the class ItemRevolver method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
ItemStack revolver = player.getHeldItem(hand);
if (!world.isRemote) {
if (player.isSneaking()) {
CommonProxy.openGuiForItem(player, hand == EnumHand.MAIN_HAND ? EntityEquipmentSlot.MAINHAND : EntityEquipmentSlot.OFFHAND);
return new ActionResult(EnumActionResult.SUCCESS, revolver);
} else if (player.getCooledAttackStrength(1) >= 1) {
if (this.getUpgrades(revolver).getBoolean("nerf"))
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 1f, 0.6f);
else {
if (getShootCooldown(revolver) > 0 || ItemNBTHelper.hasKey(revolver, "reload"))
return new ActionResult(EnumActionResult.PASS, revolver);
NonNullList<ItemStack> bullets = getBullets(revolver);
if (isEmpty(revolver, false))
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack stack = player.inventory.getStackInSlot(i);
if (stack.getItem() instanceof ItemSpeedloader && !((ItemSpeedloader) stack.getItem()).isEmpty(stack)) {
for (ItemStack b : bullets) if (!b.isEmpty())
world.spawnEntity(new EntityItem(world, player.posX, player.posY, player.posZ, b));
setBullets(revolver, ((ItemSpeedloader) stack.getItem()).getContainedItems(stack), true);
((ItemSpeedloader) stack.getItem()).setContainedItems(stack, NonNullList.withSize(8, ItemStack.EMPTY));
player.inventory.markDirty();
if (player instanceof EntityPlayerMP)
ImmersiveEngineering.packetHandler.sendTo(new MessageSpeedloaderSync(i, hand), (EntityPlayerMP) player);
ItemNBTHelper.setInt(revolver, "reload", 60);
return new ActionResult(EnumActionResult.SUCCESS, revolver);
}
}
if (!ItemNBTHelper.hasKey(revolver, "reload")) {
if (!bullets.get(0).isEmpty() && bullets.get(0).getItem() instanceof ItemBullet && ItemNBTHelper.hasKey(bullets.get(0), "bullet")) {
String key = ItemNBTHelper.getString(bullets.get(0), "bullet");
IBullet bullet = BulletHandler.getBullet(key);
if (bullet != null) {
Vec3d vec = player.getLookVec();
boolean electro = getUpgrades(revolver).getBoolean("electro");
int count = bullet.getProjectileCount(player);
if (count == 1) {
Entity entBullet = getBullet(player, vec, vec, key, bullets.get(0), electro);
player.world.spawnEntity(bullet.getProjectile(player, bullets.get(0), entBullet, electro));
} else
for (int i = 0; i < count; i++) {
Vec3d vecDir = vec.add(player.getRNG().nextGaussian() * .1, player.getRNG().nextGaussian() * .1, player.getRNG().nextGaussian() * .1);
Entity entBullet = getBullet(player, vec, vecDir, key, bullets.get(0), electro);
player.world.spawnEntity(bullet.getProjectile(player, bullets.get(0), entBullet, electro));
}
bullets.set(0, bullet.getCasing(bullets.get(0)).copy());
float noise = 0.5f;
if (hasUpgradeValue(revolver, RevolverPerk.NOISE.getNBTKey()))
noise *= (float) getUpgradeValue_d(revolver, RevolverPerk.NOISE.getNBTKey());
Utils.attractEnemies(player, 64 * noise);
SoundEvent sound = bullet.getSound();
if (sound == null)
sound = IESounds.revolverFire;
world.playSound(null, player.posX, player.posY, player.posZ, sound, SoundCategory.PLAYERS, noise, 1f);
} else
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_HAT, SoundCategory.PLAYERS, 1f, 1f);
} else
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_HAT, SoundCategory.PLAYERS, 1f, 1f);
rotateCylinder(revolver, player, true, bullets);
ItemNBTHelper.setInt(revolver, "cooldown", getMaxShootCooldown(revolver));
return new ActionResult(EnumActionResult.SUCCESS, revolver);
}
}
}
} else if (!player.isSneaking() && revolver.getItemDamage() == 0) {
if (getShootCooldown(revolver) > 0 || ItemNBTHelper.hasKey(revolver, "reload"))
return new ActionResult(EnumActionResult.PASS, revolver);
NonNullList<ItemStack> bullets = getBullets(revolver);
if (!bullets.get(0).isEmpty() && bullets.get(0).getItem() instanceof ItemBullet && ItemNBTHelper.hasKey(bullets.get(0), "bullet")) {
Triple<ItemStack, ShaderRegistryEntry, ShaderCase> shader = ShaderRegistry.getStoredShaderAndCase(revolver);
if (shader != null) {
Vec3d pos = Utils.getLivingFrontPos(player, .75, player.height * .75, hand == EnumHand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite(), false, 1);
shader.getMiddle().getEffectFunction().execute(world, shader.getLeft(), revolver, shader.getRight().getShaderType(), pos, player.getForward(), .125f);
}
}
return new ActionResult(EnumActionResult.SUCCESS, revolver);
}
return new ActionResult(EnumActionResult.SUCCESS, revolver);
}
use of org.apache.commons.lang3.tuple.Triple in project alluxio by Alluxio.
the class AlluxioWorkerRestServiceHandler method getWebUIConfiguration.
/**
* Gets Web UI ServerConfiguration page data.
*
* @return the response object
*/
@GET
@Path(WEBUI_CONFIG)
public Response getWebUIConfiguration() {
return RestUtils.call(() -> {
WorkerWebUIConfiguration response = new WorkerWebUIConfiguration();
response.setWhitelist(mBlockWorker.getWhiteList());
TreeSet<Triple<String, String, String>> sortedProperties = new TreeSet<>();
Set<String> alluxioConfExcludes = Sets.newHashSet(PropertyKey.WORKER_WHITELIST.toString());
for (ConfigProperty configProperty : mBlockWorker.getConfiguration(GetConfigurationPOptions.newBuilder().setRawValue(true).build()).toProto().getClusterConfigsList()) {
String confName = configProperty.getName();
if (!alluxioConfExcludes.contains(confName)) {
sortedProperties.add(new ImmutableTriple<>(confName, ConfigurationUtils.valueAsString(configProperty.getValue()), configProperty.getSource()));
}
}
response.setConfiguration(sortedProperties);
return response;
}, ServerConfiguration.global());
}
use of org.apache.commons.lang3.tuple.Triple in project midpoint by Evolveum.
the class TestAssignmentProcessor2 method test020AssignMR1ToR1.
@Test(enabled = FIRST_PART)
public void test020AssignMR1ToR1() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = getTestOperationResult();
LensContext<RoleType> context = createContextForAssignment(RoleType.class, ROLE_R1_OID, RoleType.class, ROLE_MR1_OID, null, null, result);
// WHEN
when();
assignmentProcessor.processAssignments(context, clock.currentTimeXMLGregorianCalendar(), task, result);
// THEN
then();
displayDumpable("Output context", context);
displayDumpable("Evaluated assignment triple", context.getEvaluatedAssignmentTriple());
assertSuccess(result);
// assignment of construction R1-0
// assignment of focus mappings R1-0
// assignment of focus policy rules R1-0
// assignment of metarole MR1 (this will be checked)
Collection<EvaluatedAssignmentImpl<RoleType>> evaluatedAssignments = assertAssignmentTripleSetSize(context, 4, 0, 0);
List<EvaluatedAssignmentImpl<RoleType>> targetedAssignments = evaluatedAssignments.stream().filter(ea -> ea.getTarget() != null).collect(Collectors.toList());
assertEquals("Wrong # of targeted assignments", 1, targetedAssignments.size());
EvaluatedAssignmentImpl<RoleType> evaluatedAssignment = targetedAssignments.get(0);
assertEquals("Wrong evaluatedAssignment.isValid", true, evaluatedAssignment.isValid());
// R4, R5, R6 could be optimized out
assertTargets(evaluatedAssignment, true, "MR1 MR3 MR4", null, null, null, null, null);
assertTargets(evaluatedAssignment, false, "MMR1 R5 R4 R6", null, null, null, null, null);
assertMembershipRef(evaluatedAssignment, "MR1 MR3 MR4");
assertOrgRef(evaluatedAssignment, "");
assertDelegation(evaluatedAssignment, null);
assertConstructions(evaluatedAssignment, "MR1-1 MR3-1 MMR1-2 MR4-1", null, null, null, null, null);
assertFocusMappings(evaluatedAssignment, "MR1-1 MR3-1 MMR1-2 MR4-1");
assertFocusPolicyRules(evaluatedAssignment, "MR1-1 MR3-1 MMR1-2 MR4-1");
assertTargetPolicyRules(evaluatedAssignment, "MR1-0 MMR1-1", "MR3-0 MR4-0");
assertAuthorizations(evaluatedAssignment, "MR1 MR3 MR4");
assertGuiConfig(evaluatedAssignment, "MR1 MR3 MR4");
assertSerializable(context);
}
use of org.apache.commons.lang3.tuple.Triple in project robovm by robovm.
the class TrampolineCompiler method compile.
public void compile(ModuleBuilder mb, Clazz currentClass, Trampoline t, Set<String> dependencies, Set<Triple<String, String, String>> methodDependencies) {
this.mb = mb;
addDependencyIfNeeded(dependencies, currentClass, t);
/*
* Check if the target class exists and is accessible. Also check that
* field accesses and method calls are compatible with the target
* field/method and that the field/method is accessible to the caller.
* If any of the tests fail the weak trampoline function created by the
* ClassCompiler will be overridden with a function which throws an
* appropriate exception.
*/
Function errorFn = new FunctionBuilder(t).linkage(external).build();
if (!checkClassExists(errorFn, t) || !checkClassAccessible(errorFn, t)) {
mb.addFunction(errorFn);
return;
}
if (t instanceof New) {
SootClass target = config.getClazzes().load(t.getTarget()).getSootClass();
if (target.isAbstract() || target.isInterface()) {
call(errorFn, BC_THROW_INSTANTIATION_ERROR, errorFn.getParameterRef(0), mb.getString(t.getTarget().replace('/', '.')));
errorFn.add(new Unreachable());
mb.addFunction(errorFn);
return;
}
String fnName = Symbols.clinitWrapperSymbol(Symbols.allocatorSymbol(t.getTarget()));
alias(t, fnName);
} else if (t instanceof Instanceof) {
if (isArray(t.getTarget())) {
FunctionRef fnRef = createInstanceofArray((Instanceof) t);
alias(t, fnRef.getName());
} else {
String fnName = Symbols.instanceofSymbol(t.getTarget());
alias(t, fnName);
}
} else if (t instanceof Checkcast) {
if (isArray(t.getTarget())) {
FunctionRef fnRef = createCheckcastArray((Checkcast) t);
alias(t, fnRef.getName());
} else {
String fnName = Symbols.checkcastSymbol(t.getTarget());
alias(t, fnName);
}
} else if (t instanceof LdcClass) {
if (isArray(t.getTarget())) {
FunctionRef fnRef = createLdcArray((LdcClass) t);
alias(t, fnRef.getName());
} else {
String fnName = Symbols.ldcExternalSymbol(t.getTarget());
alias(t, fnName);
}
} else if (t instanceof Anewarray) {
FunctionRef fnRef = createAnewarray((Anewarray) t);
alias(t, fnRef.getName());
} else if (t instanceof Multianewarray) {
FunctionRef fnRef = createMultianewarray((Multianewarray) t);
alias(t, fnRef.getName());
} else if (t instanceof FieldAccessor) {
SootField field = resolveField(errorFn, (FieldAccessor) t);
if (field != null) {
dependencies.add(getInternalName(field.getDeclaringClass()));
}
if (field == null || !checkMemberAccessible(errorFn, t, field)) {
mb.addFunction(errorFn);
return;
}
Clazz caller = config.getClazzes().load(t.getCallingClass());
Clazz target = config.getClazzes().load(t.getTarget());
if (!((FieldAccessor) t).isGetter() && field.isFinal() && caller != target) {
// Only the class declaring a final field may write to it.
// (Actually only <init>/<clinit> methods may write to it but we
// don't know which method is accessing the field at this point)
throwIllegalAccessError(errorFn, ATTEMPT_TO_WRITE_TO_FINAL_FIELD, target, field.getName(), caller);
mb.addFunction(errorFn);
return;
}
if (!field.isStatic()) {
createInlinedAccessorForInstanceField((FieldAccessor) t, field);
} else {
createTrampolineAliasForField((FieldAccessor) t, field);
}
} else if (t instanceof Invokeinterface) {
SootMethod rm = resolveInterfaceMethod(errorFn, (Invokeinterface) t);
if (rm != null) {
methodDependencies.add(new ImmutableTriple<String, String, String>(getInternalName(rm.getDeclaringClass()), rm.getName(), getDescriptor(rm)));
}
if (rm == null || !checkMemberAccessible(errorFn, t, rm)) {
mb.addFunction(errorFn);
return;
}
createTrampolineAliasForMethod((Invoke) t, rm);
} else if (t instanceof Invoke) {
SootMethod method = resolveMethod(errorFn, (Invoke) t);
if (method != null) {
methodDependencies.add(new ImmutableTriple<String, String, String>(getInternalName(method.getDeclaringClass()), method.getName(), getDescriptor(method)));
}
if (method == null || !checkMemberAccessible(errorFn, t, method)) {
mb.addFunction(errorFn);
return;
}
if (t instanceof Invokespecial && method.isAbstract()) {
call(errorFn, BC_THROW_ABSTRACT_METHOD_ERROR, errorFn.getParameterRef(0), mb.getString(String.format(NO_SUCH_METHOD_ERROR, method.getDeclaringClass(), method.getName(), getDescriptor(method))));
errorFn.add(new Unreachable());
mb.addFunction(errorFn);
return;
}
createTrampolineAliasForMethod((Invoke) t, method);
}
}
use of org.apache.commons.lang3.tuple.Triple in project alluxio by Alluxio.
the class PermissionCheckTest method getPermissionOther.
@Test
public void getPermissionOther() throws Exception {
ArrayList<Triple<String, String, Mode>> permissions = new ArrayList<>();
permissions.add(new ImmutableTriple<>(TEST_USER_1.getUser(), TEST_USER_1.getGroup(), new Mode((short) 0754)));
LockedInodePath lockedInodePath = getLockedInodePath(permissions);
try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(TEST_USER_2.getUser())) {
PermissionChecker checker = new PermissionChecker(mInodeTree);
Mode.Bits actual = checker.getPermission(lockedInodePath);
Assert.assertEquals(Mode.Bits.READ, actual);
}
}
Aggregations