use of org.spongepowered.api.event.Event in project guardian by ichorpowered.
the class VerticalSpeedCheck method getSequence.
@Nonnull
@Override
public SequenceBlueprint<Event> getSequence(final Detection detection) {
final Double analysisTime = detection.getContentContainer().get(ContentKeys.ANALYSIS_TIME).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
final Double minimumTickRate = detection.getContentContainer().get(ContentKeys.ANALYSIS_MINIMUM_TICK).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
final Double maximumTickRate = detection.getContentContainer().get(ContentKeys.ANALYSIS_MAXIMUM_TICK).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
return new GuardianSequenceBuilder().capture(new ControlCapture(detection.getPlugin(), detection)).capture(new PotionEffectCapture(detection.getPlugin(), detection)).observe(MoveEntityEvent.class).after().delay(analysisTime.intValue()).condition(sequenceContext -> {
final GuardianPlayerEntry<Player> entityEntry = sequenceContext.get(CommonContextKeys.ENTITY_ENTRY);
final Summary summary = sequenceContext.get(CommonContextKeys.SUMMARY);
final GuardianCaptureRegistry captureRegistry = sequenceContext.get(CommonContextKeys.CAPTURE_REGISTRY);
final long lastActionTime = sequenceContext.get(CommonContextKeys.LAST_ACTION_TIME);
summary.set(SequenceReport.class, new SequenceReport(false, Origin.source(sequenceContext.getRoot()).owner(entityEntry).build()));
if (!entityEntry.getEntity(Player.class).isPresent())
return false;
Player player = entityEntry.getEntity(Player.class).get();
/*
* Capture Collection
*/
final CaptureContainer captureContainer = captureRegistry.getContainer();
Optional<Location> initial = captureContainer.get(GuardianSequence.INITIAL_LOCATION);
Optional<Double> verticalOffset = captureContainer.get(ControlCapture.VERTICAL_DISTANCE);
if (!initial.isPresent() || !verticalOffset.isPresent())
return false;
long current = System.currentTimeMillis();
// Finds the average between now and the last action.
double averageClockRate = ((current - lastActionTime) / 1000) / 0.05;
if (averageClockRate < minimumTickRate) {
detection.getLogger().warn("The server may be overloaded. A check could not be completed.");
return false;
} else if (averageClockRate > maximumTickRate) {
return false;
}
if (player.get(Keys.VEHICLE).isPresent())
return false;
double verticalDisplacement = MathUtil.truncateDownTo(player.getLocation().getY() - initial.get().getY(), 4);
double verticalPlacement = MathUtil.truncateDownTo((verticalOffset.get() * (verticalOffset.get() / 0.2)) / averageClockRate + 0.1, 4);
if (verticalDisplacement < 1 || verticalOffset.get() < 1)
return false;
if (verticalDisplacement > verticalPlacement) {
// ------------------------- DEBUG -----------------------------
System.out.println(player.getName() + " has been caught using vertical speed hacks. (" + (verticalDisplacement - verticalPlacement) + ")");
// -------------------------------------------------------------
SequenceReport report = new SequenceReport(true, Origin.source(sequenceContext.getRoot()).owner(entityEntry).build());
report.put("type", "Vertical Speed");
report.put("information", Collections.singletonList("Overshot maximum movement by " + (verticalDisplacement - verticalPlacement) + "."));
report.put("initial_location", initial.get());
report.put("final_location", player.getLocation());
report.put("severity", (verticalDisplacement - verticalPlacement) / verticalDisplacement);
summary.set(SequenceReport.class, report);
return true;
}
return false;
}, ConditionType.NORMAL).build(SequenceContext.builder().owner(detection).root(this).build());
}
use of org.spongepowered.api.event.Event in project guardian by ichorpowered.
the class GuardianBypassTicket method close.
@Override
public void close() {
this.closed = true;
this.detectionTypes.forEach(detectionType -> {
if (detectionType instanceof AbstractDetection) {
AbstractDetection detection = (AbstractDetection) detectionType;
while (detection.getStageCycle().next()) {
if (detection.getStageCycle().getModel().isPresent() && CheckModel.class.isAssignableFrom(detection.getStageCycle().getModel().get().getClass())) {
if (!detection.getStageCycle().<Check<Event>>getStage().isPresent())
continue;
final Check<Event> check = detection.getStageCycle().<Check<Event>>getStage().get();
final GuardianPlayerEntry<Player> playerEntry = GuardianPlayerEntry.of(this.player, this.player.getUniqueId());
for (long id : this.blockId) {
this.plugin.getSequenceManager().unblock(SequenceContext.builder().id(id).owner(playerEntry.getUniqueId()).root(check.getSequenceTrigger()).custom(CommonContextKeys.ENTITY_ENTRY, playerEntry).build());
}
}
}
}
});
}
use of org.spongepowered.api.event.Event in project LanternServer by LanternPowered.
the class BanConfig method addBan.
@Override
public Optional<? extends Ban> addBan(Ban ban) {
checkNotNull(ban, "ban");
final Optional<Ban> oldBan;
if (ban instanceof Ban.Ip) {
oldBan = (Optional) getBanFor(((Ban.Ip) ban).getAddress());
} else {
oldBan = (Optional) getBanFor(((Ban.Profile) ban).getProfile());
}
oldBan.ifPresent(this.entries0::remove);
this.entries0.add((BanEntry) ban);
if (!oldBan.isPresent() || !oldBan.get().equals(ban)) {
final CauseStack causeStack = CauseStack.currentOrEmpty();
// Post the ban events
final Event event;
final Cause cause = causeStack.getCurrentCause();
if (ban instanceof Ban.Ip) {
event = SpongeEventFactory.createBanIpEvent(cause, (Ban.Ip) ban);
} else {
final Ban.Profile profileBan = (Ban.Profile) ban;
// Check if the pardoned player is online (not yet been kicked)
final Optional<Player> optTarget = Sponge.getServer().getPlayer(profileBan.getProfile().getUniqueId());
if (optTarget.isPresent()) {
event = SpongeEventFactory.createBanUserEventTargetPlayer(cause, profileBan, optTarget.get(), optTarget.get());
} else {
event = SpongeEventFactory.createBanUserEvent(cause, profileBan, Lantern.getGame().getServiceManager().provideUnchecked(UserStorageService.class).getOrCreate(profileBan.getProfile()));
}
}
// Just ignore for now the fact that they may be cancellable,
// only the PardonIpEvent seems to be cancellable
// TODO: Should they all be cancellable or none of them?
Sponge.getEventManager().post(event);
}
return oldBan;
}
Aggregations