Rewrite event system and optimize events. Add day counter to min menu.

This commit is contained in:
ThisIsALegitUsername 2023-01-11 04:22:49 +00:00
parent d209a8cf3c
commit e7df3fb984
26 changed files with 30674 additions and 31633 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2,31 +2,26 @@ package dev.resent;
import dev.resent.event.impl.Event;
import dev.resent.module.base.ModManager;
import net.kyori.event.EventBus;
import net.minecraft.client.Minecraft;
public class Resent {
static {
INSTANCE = new Resent();
}
public static String NAME = "Resent";
public static double VERSION = 3.3;
public static Minecraft mc = Minecraft.getMinecraft();
public static EventBus<Event> eventBus;
public static Resent INSTANCE;
static {
INSTANCE = new Resent();
eventBus = EventBus.create(Event.class);
}
public ModManager modManager;
public void init() {
Resent.INSTANCE.modManager = new ModManager();
}
public EventBus<Event> events() {
return eventBus;
public static void onEvent(Event e){
}
}

View File

@ -1,5 +1,31 @@
package dev.resent.event.impl;
public class Event{
public abstract class Event{
public abstract boolean isCancelled();
public abstract void setCancelled(boolean cancelled);
public void setType(EventType type) { this.type = type; }
public EventType getType() { return type; }
public EventType type;
public boolean isPre(){
if(type == null)
return false;
return type == EventType.pre;
}
public boolean isPost(){
if(type == null)
return false;
return type == EventType.post;
}
public enum EventType {
pre,
post;
}
}

View File

@ -1,23 +1,16 @@
package dev.resent.event.impl;
import net.kyori.event.Cancellable;
import net.minecraft.entity.Entity;
public class EventAttack extends Event implements Cancellable{
public class EventAttack extends Event{
public Entity target;
private boolean cancelled;
public boolean cancelled;
public Entity getTarget() { return target; }
public void setTarget(Entity target) { this.target = target; }
public EventAttack(Entity target) { this.target = target; }
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
public boolean isCancelled() { return cancelled; }
@Override
public void setCancelled(boolean cancelled) { this.cancelled = cancelled; }
}

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import dev.resent.Resent;
import dev.resent.event.impl.Event;
import dev.resent.setting.Setting;
import net.minecraft.client.Minecraft;
@ -34,11 +36,8 @@ public class Mod {
this.settings.addAll(Arrays.asList(settings));
}
public void onEnable() {
}
public void onDisable() {
}
public void onEnable() { }
public void onDisable() { }
public void toggle() {
this.enabled = !this.enabled;
@ -49,6 +48,14 @@ public class Mod {
}
}
public void onEvent(Event e){
for(int i = 0; i < Resent.INSTANCE.modManager.modules.size(); i++){
if(!Resent.INSTANCE.modManager.modules.get(i).isEnabled())
continue;
Resent.INSTANCE.modManager.modules.get(i).onEvent(e);
}
}
public void setEnabled(boolean state) {
this.enabled = state;
if (this.enabled)

View File

@ -1,6 +1,6 @@
package dev.resent.module.impl.hud;
import dev.resent.Resent;
import dev.resent.event.impl.Event;
import dev.resent.event.impl.EventAttack;
import dev.resent.module.base.Category;
import dev.resent.module.base.RenderModule;
@ -16,12 +16,12 @@ public class ComboCounter extends RenderModule {
public ComboCounter() {
super("ComboCounter", Category.HUD, 4, 4, true);
addSetting(tshadow);
}
Resent.INSTANCE.events().subscribe(EventAttack.class, event -> {
if (this.isEnabled()) {
public void onEvent(Event e){
if(e instanceof EventAttack && isEnabled()){
attacked = true;
}
});
}
}
public void onEntityHit(S19PacketEntityStatus event) {

View File

@ -2,7 +2,7 @@ package dev.resent.module.impl.hud;
import java.text.DecimalFormat;
import dev.resent.Resent;
import dev.resent.event.impl.Event;
import dev.resent.event.impl.EventAttack;
import dev.resent.module.base.Category;
import dev.resent.module.base.RenderModule;
@ -14,16 +14,6 @@ public class ReachDisplay extends RenderModule {
public static double range;
public ReachDisplay() {
super("ReachDisplay", Category.HUD, 4, 34);
Resent.INSTANCE.events().subscribe(EventAttack.class, event -> {
if (this.isEnabled()) {
Vec3 vec3 = this.mc.getRenderViewEntity().getPositionEyes(1.0f);
range = this.mc.objectMouseOver.hitVec.distanceTo(vec3);
if (range > 3.0f && !mc.playerController.isInCreativeMode()) {
range = 3.0f;
}
}
});
}
public int getWidth(){ return mc.fontRendererObj.getStringWidth("[" + df2.format(range) + " Blocks]")+4; }
@ -33,5 +23,16 @@ public class ReachDisplay extends RenderModule {
public void draw() {
mc.fontRendererObj.drawStringWithShadow("[" + df2.format(range) + " Blocks]", this.x + 2, this.y + 2, -1);
}
@Override
public void onEvent(Event e){
if(e instanceof EventAttack && e.isPre() && isEnabled()){
Vec3 vec3 = this.mc.getRenderViewEntity().getPositionEyes(1.0f);
range = this.mc.objectMouseOver.hitVec.distanceTo(vec3);
if (range > 3.0f && !mc.playerController.isInCreativeMode()) {
range = 3.0f;
}
}
}
}

View File

@ -8,7 +8,7 @@ public class FPSB extends Mod{
public static boolean yes = false;
public FPSB(){
super("Fps Boost", Category.MISC);
super("Fast math", Category.MISC);
}
@Override

View File

@ -1,47 +0,0 @@
/*
* This file is part of event, licensed under the MIT License.
*
* Copyright (c) 2017-2021 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.event;
/**
* An abstract implementation of a cancellable event.
*
* <p>This implementation is not always possible to use if {@link EventBus} requires events
* to implement an {@code abstract} class.</p>
*
* @since 5.0.0
*/
public abstract class AbstractCancellable implements Cancellable {
// protected to allow children classes to access
protected boolean cancelled;
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(final boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,47 +0,0 @@
/*
* This file is part of event, licensed under the MIT License.
*
* Copyright (c) 2017-2021 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.event;
/**
* A cancellable event.
*
* @since 1.0.0
*/
public interface Cancellable {
/**
* Tests if the event has been cancelled.
*
* @return {@code true} if the event has been cancelled, {@code false} otherwise
* @since 1.0.0
*/
boolean isCancelled();
/**
* Sets the cancelled state of the event.
*
* @param cancelled {@code true} if the event should be cancelled, {@code false} otherwise
* @since 1.0.0
*/
void setCancelled(final boolean cancelled);
}

View File

@ -1,142 +0,0 @@
/*
* This file is part of event, licensed under the MIT License.
*
* Copyright (c) 2017-2021 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.event;
import java.util.function.Predicate;
/**
* An event bus.
*
* @param <E> the event type
* @since 5.0.0
*/
public interface EventBus<E> {
/**
* Creates an event bus.
*
* @param type the event type
* @param <E> the event type
* @return an event bus
* @since 5.0.0
*/
static <E> EventBus<E> create(final Class<E> type) {
return create(type, Accepts.nonCancelledWhenNotAcceptingCancelled());
}
/**
* Creates an event bus.
*
* @param type the event type
* @param <E> the event type
* @return an event bus
* @since 5.0.0
*/
static <E> EventBus<E> create(final Class<E> type, final Accepts<E> accepts) {
return new EventBusImpl<>(type, accepts);
}
/**
* Gets the type of events accepted by this event bus.
*
* <p>
* This is represented by the <code>E</code> type parameter.
* </p>
*
* @return the event type
* @since 5.0.0
*/
Class<E> type();
/**
* Posts an event to all registered subscribers.
*
* @param event the event
* @return the post result of the operation
* @since 2.0.0
*/
PostResult post(final E event);
/**
* Determines whether or not the specified event has been subscribed to.
*
* @param type the event type
* @return {@code true} if the event has subscribers, {@code false} otherwise
* @since 5.0.0
*/
boolean subscribed(final Class<? extends E> type);
/**
* Registers the given {@code subscriber} to receive events.
*
* @param event the event type
* @param subscriber the subscriber
* @param <T> the event type
* @return an event subscription
* @since 5.0.0
*/
<T extends E> EventSubscription subscribe(final Class<T> event, final EventSubscriber<? super T> subscriber);
/**
* Unregisters all subscribers matching the {@code predicate}.
*
* @param predicate the predicate to test subscribers for removal
* @since 5.0.0
*/
void unsubscribeIf(final Predicate<EventSubscriber<? super E>> predicate);
/**
* An acceptor.
*
* @param <E> the event type
* @since 5.0.0
*/
interface Accepts<E> {
/**
* The default acceptor.
*
* @param <E> the event type
* @return the default acceptor
* @since 5.0.0
*/
static <E> Accepts<E> nonCancelledWhenNotAcceptingCancelled() {
return (type, event, subscriber) -> {
if (!subscriber.acceptsCancelled()) {
return !(event instanceof Cancellable) || !((Cancellable) event).isCancelled();
}
return true;
};
}
/**
* Tests if a subscriber accepts an event.
*
* @param type the event type
* @param event the event
* @param subscriber the event subscriber
* @return {@code true} if {@code subscriber} accepts the {@code event}
* @since 5.0.0
*/
boolean accepts(final Class<E> type, final E event, final EventSubscriber<? super E> subscriber);
}
}

View File

@ -1,160 +0,0 @@
/*
* This file is part of event, licensed under the MIT License.
*
* Copyright (c) 2017-2021 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.event;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
final class EventBusImpl<E> implements EventBus<E> {
private static final Comparator<EventSubscriber<?>> COMPARATOR = Comparator.comparingInt(EventSubscriber::postOrder);
private final Map<Class<? extends E>, Collection<? extends Class<?>>> classes = new HashMap<>();
private final Map<Class<? extends E>, List<EventSubscriber<? super E>>> unbaked = new HashMap<>();
private final Map<Class<? extends E>, List<EventSubscriber<? super E>>> baked = new HashMap<>();
private final Object lock = new Object();
private final Class<E> type;
private final Accepts<E> accepts;
EventBusImpl(final Class<E> type, final Accepts<E> accepts) {
this.type = type;
this.accepts = accepts;
}
@Override
public Class<E> type() {
return this.type;
}
@Override
@SuppressWarnings("unchecked")
public PostResult post(final E event) {
Map<EventSubscriber<?>, Throwable> exceptions = null; // save on an allocation
final List<EventSubscriber<? super E>> subscribers = this.subscribers((Class<? extends E>) event.getClass());
for (final EventSubscriber<? super E> subscriber : subscribers) {
if (this.accepts(event, subscriber)) {
try {
subscriber.on(event);
} catch (final Throwable t) {
if (exceptions == null) {
exceptions = new HashMap<>();
}
exceptions.put(subscriber, t);
}
}
}
if (exceptions == null) {
return PostResult.success();
} else {
return PostResult.failure(exceptions);
}
}
private boolean accepts(final E event, final EventSubscriber<? super E> subscriber) {
return this.accepts.accepts(this.type, event, subscriber);
}
@Override
public boolean subscribed(final Class<? extends E> type) {
return !this.subscribers(type).isEmpty();
}
@Override
public <T extends E> EventSubscription subscribe(final Class<T> event,
final EventSubscriber<? super T> subscriber) {
synchronized (this.lock) {
final List<EventSubscriber<? super T>> subscribers = yayGenerics(
this.unbaked.computeIfAbsent(event, key -> new ArrayList<>()));
subscribers.add(subscriber);
this.baked.clear();
}
return () -> {
synchronized (this.lock) {
final List<EventSubscriber<? super T>> subscribers = yayGenerics(this.unbaked.get(event));
if (subscribers != null) {
subscribers.remove(subscriber);
this.baked.clear();
}
}
};
}
@Override
public void unsubscribeIf(final Predicate<EventSubscriber<? super E>> predicate) {
synchronized (this.lock) {
boolean dirty = false;
for (final List<EventSubscriber<? super E>> subscribers : this.unbaked.values()) {
dirty |= subscribers.removeIf(predicate);
}
if (dirty) {
this.baked.clear();
}
}
}
private List<EventSubscriber<? super E>> subscribers(final Class<? extends E> event) {
synchronized (this.lock) {
return this.baked.computeIfAbsent(event, this::subscribers0);
}
}
private List<EventSubscriber<? super E>> subscribers0(final Class<? extends E> event) {
final List<EventSubscriber<? super E>> subscribers = new ArrayList<>();
final Collection<? extends Class<?>> types = this.classes.computeIfAbsent(event, this::findClasses);
for (final Class<?> type : types) {
subscribers.addAll(this.unbaked.getOrDefault(type, Collections.emptyList()));
}
subscribers.sort(COMPARATOR);
return subscribers;
}
private Collection<? extends Class<?>> findClasses(final Class<?> type) {
final Collection<? extends Class<?>> classes = Internals.ancestors(type);
removeIf(classes, klass -> !this.type.isAssignableFrom(klass));
return classes;
}
@SuppressWarnings("unchecked")
private static <T extends U, U> List<U> yayGenerics(final List<T> list) {
return (List<U>) list;
}
private static <T> boolean removeIf(Collection<T> collection, Predicate<T> pre) {
boolean ret = false;
Iterator<T> itr = collection.iterator();
while (itr.hasNext()) {
if (pre.test(itr.next())) {
itr.remove();
ret = true;
}
}
return ret;
}
}

View File

@ -1,62 +0,0 @@
/*
* This file is part of event, licensed under the MIT License.
*
* Copyright (c) 2017-2021 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.event;
/**
* An event subscriber.
*
* @param <E> the event type
* @since 2.0.0
*/
@FunctionalInterface
public interface EventSubscriber<E> {
/**
* Invokes this event subscriber.
*
* @param event the event
* @since 5.0.0
*/
void on(final E event) throws Throwable;
/**
* Gets the post order this subscriber should be called at.
*
* @return the post order of this subscriber
* @since 2.0.0
*/
default int postOrder() {
return PostOrders.NORMAL;
}
/**
* Gets if cancelled events should be consumed by this subscriber.
*
* @return {@code true} if cancelled events should be consumed, {@code false}
* otherwise
* @since 5.0.0
*/
default boolean acceptsCancelled() {
return true;
}
}

View File

@ -1,39 +0,0 @@
/*
* This file is part of event, licensed under the MIT License.
*
* Copyright (c) 2017-2021 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.event;
/**
* An event subscription.
*
* @since 5.0.0
*/
@FunctionalInterface
public interface EventSubscription {
/**
* Unsubscribes, preventing the subscriber behind this subscription from receiving any more events.
*
* @since 5.0.0
*/
void unsubscribe();
}

View File

@ -1,79 +0,0 @@
/*
* This file is part of event, licensed under the MIT License.
*
* Copyright (c) 2017-2021 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.event;
import java.util.ArrayList;
import java.util.List;
final class Internals {
private Internals() {
}
// https://github.com/Kaoaki/ksl/blob/master/src/main/java/net/kaoaki/ksl/reflection/Types.java
/*
* This file is part of ksl, licensed under the MIT License.
*
* Copyright (c) 2021 Kaoaki
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
@SuppressWarnings("unchecked")
static <T> List<Class<? super T>> ancestors(final Class<T> type) {
final List<Class<? super T>> types = new ArrayList<>();
types.add(type);
for (int i = 0; i < types.size(); i++) {
final Class<?> next = types.get(i);
final Class<?> superclass = next.getSuperclass();
if (superclass != null) {
types.add((Class<? super T>) superclass);
}
final Class<?>[] interfaces = next.getInterfaces();
for (final Class<?> iface : interfaces) {
// we have a list because we want to preserve order, but we don't want
// duplicates
if (!types.contains(iface)) {
types.add((Class<? super T>) iface);
}
}
}
return types;
}
}

View File

@ -1,68 +0,0 @@
/*
* This file is part of event, licensed under the MIT License.
*
* Copyright (c) 2017-2021 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.event;
/**
* The "post order" is a representation of the order, relative to other posts,
* that a given {@link EventSubscriber} should be posted events.
*
* <p>Post orders are represented by {@link Integer}s, and subscribers are
* ordered using the natural ordering of Java integers.</p>
*
* <p>Some "standard" post orders are expressed as constants on this class.</p>
*
* @since 3.0.0
*/
public interface PostOrders {
/**
* Marks that the subscriber should be called first, before all other subscribers.
*
* @since 3.0.0
*/
int FIRST = -100;
/**
* Marks that the subscriber should be called before {@link #NORMAL normal} subscribers.
*
* @since 3.0.0
*/
int EARLY = -50;
/**
* Marks that the subscriber should be called with no special priority.
*
* @since 3.0.0
*/
int NORMAL = 0;
/**
* Marks that the subscriber should be called after {@link #NORMAL normal} subscribers.
*
* @since 3.0.0
*/
int LATE = 50;
/**
* Marks that the subscriber should be called last, after all other subscribers.
*
* @since 3.0.0
*/
int LAST = 100;
}

View File

@ -1,181 +0,0 @@
/*
* This file is part of event, licensed under the MIT License.
*
* Copyright (c) 2017-2021 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.event;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Encapsulates the outcome of a {@link EventBus#post(Object)} call.
*
* @since 2.0.0
*/
public abstract class PostResult {
PostResult() {
if (!(this instanceof Success || this instanceof Failure)) {
throw new IllegalStateException();
}
}
/**
* Marks that no exceptions were thrown by subscribers.
*
* @return a {@link PostResult} indicating success
* @since 2.0.0
*/
public static PostResult success() {
return Success.INSTANCE;
}
/**
* Marks that exceptions were thrown by subscribers.
*
* @param exceptions the exceptions that were thrown
* @return a {@link PostResult} indicating failure
* @since 2.0.0
*/
public static PostResult failure(final Map<EventSubscriber<?>, Throwable> exceptions) {
if (exceptions.isEmpty()) {
throw new IllegalStateException("no exceptions present");
}
return new Failure(new HashMap<>(exceptions));
}
/**
* Gets if the {@link EventBus#post(Object)} call was successful.
*
* @return if the call was successful
* @since 2.0.0
*/
public abstract boolean wasSuccessful();
/**
* Gets the exceptions that were thrown whilst posting the event to subscribers.
*
* @return the exceptions thrown by subscribers
* @since 3.0.0
*/
public abstract Map<EventSubscriber<?>, Throwable> exceptions();
/**
* Raises a {@link CompositeException} if the posting was not
* {@link #wasSuccessful() successful}.
*
* @throws CompositeException if posting was not successful
* @since 3.0.0
*/
public abstract void raise() throws CompositeException;
@Override
public abstract String toString();
private static final class Success extends PostResult {
static final Success INSTANCE = new Success();
@Override
public boolean wasSuccessful() {
return true;
}
@Override
public Map<EventSubscriber<?>, Throwable> exceptions() {
return Collections.emptyMap();
}
@Override
public void raise() {
}
@Override
public String toString() {
return "PostResult.success()";
}
}
private static final class Failure extends PostResult {
private final Map<EventSubscriber<?>, Throwable> exceptions;
private Failure(final Map<EventSubscriber<?>, Throwable> exceptions) {
this.exceptions = exceptions;
}
@Override
public boolean wasSuccessful() {
return this.exceptions.isEmpty();
}
@Override
public Map<EventSubscriber<?>, Throwable> exceptions() {
return this.exceptions;
}
@Override
public void raise() throws CompositeException {
throw new CompositeException(this);
}
@Override
public String toString() {
return "PostResult.failure(" + this.exceptions + ")";
}
}
/**
* Exception encapsulating a combined {@link #failure(Map) failure}.
*
* @since 3.0.0
*/
public static final class CompositeException extends Exception {
private final PostResult result;
CompositeException(final PostResult result) {
super("Exceptions occurred whilst posting to subscribers");
this.result = result;
}
/**
* Gets the result that created this composite exception.
*
* @return the result
* @since 5.0.0
*/
public PostResult result() {
return this.result;
}
/**
* Prints all of the stack traces involved in the composite exception.
*
* @see Exception#printStackTrace()
* @since 5.0.0
*/
public void printAllStackTraces() {
this.printStackTrace();
for (final Throwable exception : this.result.exceptions().values()) {
exception.printStackTrace();
}
}
}
}

View File

@ -97,41 +97,7 @@ public class GuiMainMenu extends GuiScreen implements GuiYesNoCallback {
private static ResourceLocation backgroundTexture = null;
public GuiMainMenu() {
this.splashText = "missingno";
BufferedReader bufferedreader = null;
try {
ArrayList arraylist = Lists.newArrayList();
bufferedreader = new BufferedReader(new InputStreamReader(
Minecraft.getMinecraft().getResourceManager().getResource(splashTexts).getInputStream(),
Charsets.UTF_8));
String s;
while ((s = bufferedreader.readLine()) != null) {
s = s.trim();
if (!s.isEmpty()) {
arraylist.add(s);
}
}
if (!arraylist.isEmpty()) {
while (true) {
this.splashText = (String) arraylist.get(RANDOM.nextInt(arraylist.size()));
if (this.splashText.hashCode() != 125780783) {
break;
}
}
}
} catch (IOException var12) {
} finally {
if (bufferedreader != null) {
try {
bufferedreader.close();
} catch (IOException var11) {
}
}
}
this.splashText = (System.currentTimeMillis() - 1672104240000l) / 86400000l + "Days since Resent last merged with Eaglercraft U5";
this.updateCounter = RANDOM.nextFloat();

View File

@ -1,8 +1,13 @@
package net.minecraft.entity.player;
import java.util.Collection;
import java.util.List;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import dev.resent.Resent;
import dev.resent.event.impl.Event.EventType;
import dev.resent.event.impl.EventAttack;
import net.lax1dude.eaglercraft.v1_8.EaglercraftUUID;
import net.lax1dude.eaglercraft.v1_8.mojang.authlib.GameProfile;
@ -14,7 +19,14 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.server.CommandBlockLogic;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.IEntityMultiPart;
import net.minecraft.entity.IMerchant;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.boss.EntityDragonPart;
import net.minecraft.entity.item.EntityBoat;
@ -32,20 +44,39 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryEnderChest;
import net.minecraft.item.*;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.potion.Potion;
import net.minecraft.scoreboard.*;
import net.minecraft.scoreboard.IScoreObjectiveCriteria;
import net.minecraft.scoreboard.Score;
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.scoreboard.ScorePlayerTeam;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.scoreboard.Team;
import net.minecraft.stats.AchievementList;
import net.minecraft.stats.StatBase;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntitySign;
import net.minecraft.util.*;
import net.minecraft.world.*;
import java.util.Collection;
import java.util.List;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.FoodStats;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.IInteractionObject;
import net.minecraft.world.LockCode;
import net.minecraft.world.World;
import net.minecraft.world.WorldSettings;
public abstract class EntityPlayer extends EntityLivingBase implements ICommandSender {
/**+
@ -992,7 +1023,8 @@ public abstract class EntityPlayer extends EntityLivingBase implements ICommandS
public void attackTargetEntityWithCurrentItem(Entity entity) {
EventAttack event = new EventAttack(entity);
Resent.INSTANCE.events().post(event);
event.setType(EventType.pre);
Resent.onEvent(event);
if (entity.canAttackWithItem()) {
if (!entity.hitByEntity(this)) {