Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation Code Cleanup #1932

Merged
merged 7 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public class SpongeTriggerBuilder<C extends FilteredTriggerConfiguration> implem
private final static Function<JsonObject, FilteredTriggerConfiguration.Empty> EMPTY_TRIGGER_CONFIGURATION_CONSTRUCTOR =
jsonObject -> EMPTY_TRIGGER_CONFIGURATION;

private Class<C> configType;
private Function<JsonObject, C> constructor;
@Nullable private Class<C> configType;
@Nullable private Function<JsonObject, C> constructor;
@Nullable private Consumer<CriterionEvent.Trigger<C>> eventHandler;
private String id;
@Nullable private String id;
@Nullable private String name;

@Override
Expand Down Expand Up @@ -193,6 +193,7 @@ public Trigger.Builder<C> name(String name) {
return this;
}

@SuppressWarnings("rawtypes")
@Override
public Trigger<C> build() {
checkState(this.id != null, "The id must be set");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public boolean flush(SpongeConfig<?> config) {
public void flush() {
if (!this.stagedConfigs.isEmpty()) {
synchronized (this) {
for (SpongeConfig spongeConfig : this.stagedConfigs) {
for (SpongeConfig<?> spongeConfig : this.stagedConfigs) {
spongeConfig.saveNow();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
import org.spongepowered.api.event.cause.EventContextKey;
import org.spongepowered.common.registry.type.event.EventContextKeysModule;

import javax.annotation.Nullable;

public final class SpongeEventContextKeyBuilder<T> implements EventContextKey.Builder<T> {

Class<T> typeClass;
String id;
String name;
@Nullable Class<T> typeClass;
@Nullable String id;
@Nullable String name;

@Override
public SpongeEventContextKeyBuilder<T> type(Class<T> aClass) {
Expand Down Expand Up @@ -72,7 +74,7 @@ public EventContextKey<T> build() {
}

@Override
public SpongeEventContextKeyBuilder<T> from(EventContextKey value) throws UnsupportedOperationException {
public SpongeEventContextKeyBuilder<T> from(EventContextKey<T> value) throws UnsupportedOperationException {
throw new UnsupportedOperationException("Cannot create a new EventContextKey based on another key!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import co.aikar.timings.Timing;
import co.aikar.timings.TimingsManager;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
Expand All @@ -50,10 +51,12 @@
import org.spongepowered.api.event.item.inventory.InteractInventoryEvent;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.plugin.PluginManager;
import org.spongepowered.asm.util.PrettyPrinter;
import org.spongepowered.common.SpongeImpl;
import org.spongepowered.common.event.filter.FilterFactory;
import org.spongepowered.common.event.gen.DefineableClassLoader;
import org.spongepowered.common.event.tracking.PhaseContext;
import org.spongepowered.common.event.tracking.PhaseTracker;
import org.spongepowered.common.event.tracking.phase.plugin.PluginPhase;
import org.spongepowered.common.interfaces.IMixinContainer;
import org.spongepowered.common.util.TypeTokenHelper;
Expand Down Expand Up @@ -211,7 +214,7 @@ private void register(List<RegisteredListener<? extends Event>> handlers) {
}

@SuppressWarnings("unchecked")
public void registerListener(PluginContainer plugin, Object listenerObject) {
private void registerListener(PluginContainer plugin, Object listenerObject) {
checkNotNull(plugin, "plugin");
checkNotNull(listenerObject, "listener");

Expand Down Expand Up @@ -241,7 +244,7 @@ public void registerListener(PluginContainer plugin, Object listenerObject) {
if (listener != null) {
String error = getHandlerErrorOrNull(method);
if (error == null) {
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "rawtypes"})
final TypeToken eventType = TypeToken.of(method.getGenericParameterTypes()[0]);
AnnotatedEventListener handler;
try {
Expand Down Expand Up @@ -372,7 +375,7 @@ public void unregisterPluginListeners(Object pluginObj) {
unregister(handler -> plugin.equals(handler.getPlugin()));
}

@SuppressWarnings({"ConstantConditions", "unchecked"})
@SuppressWarnings({"ConstantConditions", "unchecked", "rawtypes"})
protected RegisteredListener.Cache getHandlerCache(Event event) {
checkNotNull(event, "event");
final Class<? extends Event> eventClass = event.getClass();
Expand Down Expand Up @@ -411,16 +414,18 @@ private boolean post(Event event, List<RegisteredListener<?>> handlers) {
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame();
final PhaseContext<?> context = PluginPhase.Listener.GENERAL_LISTENER.createPhaseContext()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra leading space?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the proper indentation since it's a multiple try with resources.

.source(handler.getPlugin())
.buildAndSwitch()) {
handler.getTimingsHandler().startTimingIfSync();
.buildAndSwitch();
final Timing timings = handler.getTimingsHandler()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as here, note how it lines up with CauseStackManager

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess he referred to it being 5 spaces instead of 4 or 8. IIRC 8 is a common standard for this. Aligning it as it is here is also used but less common. As always: styles are just personal preferences.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, looked really odd to me

timings.startTimingIfSync();
if (event instanceof AbstractEvent) {
((AbstractEvent) event).currentOrder = handler.getOrder();
}
handler.handle(event);
} catch (Throwable e) {
// TODO - add some better handling, especially since we have the stakc frame and phase context to boot
final PrettyPrinter printer = new PrettyPrinter(60).add("Error with event listener handling").centre().hr();
printer.add("A listener threw an exception while being handled, this is usually not a sponge bug.")
this.logger.error("Could not pass {} to {}", event.getClass().getSimpleName(), handler.getPlugin(), e);
} finally {
handler.getTimingsHandler().stopTimingIfSync();
}
Sponge.getCauseStackManager().popCause();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ public PhaseContext<?> getCurrentContext() {
* @param sourceBlock The source block type
* @param sourcePos The source block position
*/
@SuppressWarnings("rawtypes")
public void notifyBlockOfStateChange(final IMixinWorldServer mixinWorld, final BlockPos notifyPos,
final Block sourceBlock, @Nullable final BlockPos sourcePos) {
final IBlockState iblockstate = ((WorldServer) mixinWorld).getBlockState(notifyPos);
Expand Down Expand Up @@ -626,6 +627,7 @@ public boolean setBlockState(final IMixinWorldServer mixinWorld, final BlockPos
* @param entity The entity
* @return True if the entity spawn was successful
*/
@SuppressWarnings("rawtypes")
public boolean spawnEntity(World world, Entity entity) {
checkNotNull(entity, "Entity cannot be null!");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public static void tickTileEntity(IMixinWorldServer mixinWorldServer, ITickable
}
}

@SuppressWarnings("rawtypes")
public static void updateTickBlock(IMixinWorldServer mixinWorld, Block block, BlockPos pos, IBlockState state, Random random) {
final WorldServer world = WorldUtil.asNative(mixinWorld);
final World apiWorld = WorldUtil.fromNative(world);
Expand Down Expand Up @@ -289,6 +290,7 @@ public static void updateTickBlock(IMixinWorldServer mixinWorld, Block block, Bl
}
}

@SuppressWarnings("rawtypes")
public static void randomTickBlock(PhaseTracker phaseTracker, IMixinWorldServer mixinWorld, Block block,
BlockPos pos, IBlockState state, Random random) {
final WorldServer world = WorldUtil.asNative(mixinWorld);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("rawtypes")
final class PostState extends GeneralState<UnwindingPhaseContext> {

@Override
Expand All @@ -49,7 +50,7 @@ public UnwindingPhaseContext createPhaseContext() {
}

@Override
public boolean canSwitchTo(IPhaseState state) {
public boolean canSwitchTo(IPhaseState<?> state) {
return state.getPhase() == TrackingPhases.GENERATION
|| state.getPhase() == TrackingPhases.PLUGIN
|| state == BlockPhase.State.RESTORING_BLOCKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
*/
package org.spongepowered.common.event.tracking.phase.generation;

final class PopulatorGenerationPhaseState extends GeneralGenerationPhaseState {
final class PopulatorGenerationPhaseState extends GeneralGenerationPhaseState<PopulatorPhaseContext> {

PopulatorGenerationPhaseState(String id) {
super(id);
}

@Override
public GenerationContext createPhaseContext() {
public PopulatorPhaseContext createPhaseContext() {
return new PopulatorPhaseContext(this)
.addEntityCaptures();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public IPhaseState<? extends PacketContext<?>> getStateForPacket(Packet<?> packe
return PacketPhase.General.UNKNOWN;
}

@SuppressWarnings({"unchecked", "rawtypes"})
public PhaseContext<?> populateContext(Packet<?> packet, EntityPlayerMP entityPlayerMP, IPhaseState<?> state, PhaseContext<?> context) {
checkNotNull(packet, "Packet cannot be null!");
checkArgument(!context.isComplete(), "PhaseContext cannot be marked as completed!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

public final class PacketPhaseUtil {

@SuppressWarnings("rawtypes")
public static void handleSlotRestore(EntityPlayer player, @Nullable Container openContainer, List<SlotTransaction> slotTransactions, boolean eventCancelled) {
for (SlotTransaction slotTransaction : slotTransactions) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public SlotCollectionIterator(Inventory parent, Fabric<TInventory> inv, Lens<TIn
this.slots = this.traverseSpanningTree(inv, lens, slots, ImmutableList.<Slot>builder()).build();
}

@SuppressWarnings("rawtypes")
private Builder<Slot> traverseSpanningTree(Fabric<TInventory> inv, Lens<TInventory, ItemStack> lens, SlotProvider<IInventory, ItemStack> slots, Builder<Slot> list) {
for (Lens<TInventory, ItemStack> child : lens.getSpanningChildren()) {
if (child instanceof SlotLens) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
*
* @param <TInventory> the Inventory Type
*/
@SuppressWarnings("rawtypes")
public class SlotAdapter<TInventory> extends AbstractInventoryAdapter<TInventory> implements Slot {

private final SlotLens<TInventory, net.minecraft.item.ItemStack> slot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.function.Function;
import java.util.function.Supplier;

@SuppressWarnings("rawtypes")
public class ReusableLens<T extends Lens<IInventory, ItemStack>> {

// InventoryAdapterClass -> LensClass -> Size -> ReusableLens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

public class SlotCollection<TInventory> extends DynamicLensCollectionImpl<TInventory, ItemStack> implements SlotProvider<TInventory, ItemStack> {

@SuppressWarnings({"rawtypes", "unchecked"})
public static class Builder {

private List<Tuple<Class<? extends SlotAdapter>, SlotLensProvider>> slotTypes = new ArrayList<>();
Expand Down Expand Up @@ -111,7 +112,7 @@ public SlotCollection(int size) {
this(size, null);
}

SlotCollection(int size, Builder builder) {
private SlotCollection(int size, Builder builder) {
super(size);
this.builder = builder;
this.populate();
Expand All @@ -123,7 +124,7 @@ private void populate() {
}
}

protected SlotLens<TInventory, ItemStack> createSlotLens(int slotIndex) {
private SlotLens<TInventory, ItemStack> createSlotLens(int slotIndex) {
return this.builder == null ? new SlotLensImpl(slotIndex, SlotAdapter.class) : this.builder.getProvider(slotIndex).createSlotLens(slotIndex);
}

Expand All @@ -140,7 +141,8 @@ public Iterable<Slot> getIterator(Inventory parent, InventoryAdapter<TInventory,
return this.getIterator(parent, adapter.getFabric(), adapter.getRootLens());
}

public Iterable<Slot> getIterator(Inventory parent, Fabric<TInventory> inv, Lens<TInventory, ItemStack> lens) {
@SuppressWarnings("unchecked")
private Iterable<Slot> getIterator(Inventory parent, Fabric<TInventory> inv, Lens<TInventory, ItemStack> lens) {
return new SlotCollectionIterator(parent, inv, lens, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ protected void init(SlotProvider<IInventory, ItemStack> slots) {

}

@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public InventoryAdapter<IInventory, ItemStack> getAdapter(Fabric<IInventory> inv, Inventory parent) {
if (this.isContainer && inv instanceof ContainerFabric) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private MutableLensSet<TInventory, TStack> depthFirstSearch(Lens<TInventory, TSt
return matches;
}

@SuppressWarnings("rawtypes")
private boolean matches(Lens<TInventory, TStack> lens, Lens<TInventory, TStack> parent, Fabric<TInventory> inventory) {
for (QueryOperation<?> operation : this.queries) {
if (((SpongeQueryOperation) operation).matches(lens, parent, inventory)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
*/
public class ReverseTransformation implements InventoryTransformation {

@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public Inventory transform(Inventory inventory) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
/**
* Queries the inventory for slots in order of the query operations.
*/
@SuppressWarnings("rawtypes")
public class SpongeQueryTransformation implements InventoryTransformation {

private final List<QueryOperation> operations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Arrays;
import java.util.List;

@SuppressWarnings("rawtypes")
public class SpongeTransformationBuilder implements InventoryTransformation.Builder {

private List<QueryOperation> operationList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public SlotLensQueryOperation(ImmutableSet<Inventory> inventories) {
this.inventories = inventories;
}

@SuppressWarnings("rawtypes")
@Override
public <TInventory, TStack> boolean matches(Lens<TInventory, TStack> lens, Lens<TInventory, TStack> parent, Fabric<TInventory> inventory) {
for (Inventory inv : this.inventories) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* 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.
*/
@org.spongepowered.api.util.annotation.NonnullByDefault
package org.spongepowered.common.item.inventory.query;
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class SpongeIngredientBuilder implements Ingredient.Builder {
private List<ItemStack> matchItems = new ArrayList<>();
private List<ItemStack> displayItems = new ArrayList<>();

@SuppressWarnings("rawtypes")
@Override
public Ingredient.Builder from(Ingredient value) {
this.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void setId(String id) {
this.idString = id;
}

@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public Optional<T> parseValue(String value) {
return Optional.ofNullable((T) ((IProperty) this).parseValue(value).orNull());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@

import java.util.Optional;

import javax.annotation.Nullable;

@SuppressWarnings("rawtypes")
@Mixin(SpongeUserInventory.class)
public abstract class MixinSpongeUserInventory implements MinecraftInventoryAdapter<IInventory>, UserInventory<User> {

Expand All @@ -71,11 +74,12 @@ public abstract class MixinSpongeUserInventory implements MinecraftInventoryAdap
protected Fabric<IInventory> inventory;
protected PlayerInventoryLens lens;

private User carrier;
private MainPlayerInventoryAdapter main;
private EquipmentInventoryAdapter equipment;
private SlotAdapter offhand;
@Nullable private User carrier;
@Nullable private MainPlayerInventoryAdapter main;
@Nullable private EquipmentInventoryAdapter equipment;
@Nullable private SlotAdapter offhand;

@SuppressWarnings("unchecked")
@Inject(method = "<init>*", at = @At("RETURN"), remap = false)
private void onConstructed(SpongeUser playerIn, CallbackInfo ci) {
// We only care about Server inventories
Expand Down
Loading