Skip to content

Commit

Permalink
chore: fix checkstyle warnings (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
skaldarnar committed Sep 9, 2021
1 parent 5a3ac34 commit 15c30f1
Show file tree
Hide file tree
Showing 22 changed files with 106 additions and 219 deletions.
17 changes: 2 additions & 15 deletions src/main/java/org/terasology/economy/WalletCommands.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2019 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.economy;

import org.terasology.economy.events.WalletTransactionEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@
// SPDX-License-Identifier: Apache-2.0
package org.terasology.economy.components;


import com.google.common.collect.Maps;
import org.terasology.gestalt.entitysystem.component.Component;

import java.util.Map;

/**
* This storage component has an infinite stack-size and capacity.
* Used for testing and simulation purposes.
* This storage component has an infinite stack-size and capacity. Used for testing and simulation purposes.
*/
public class InfiniteStorageComponent implements Component<InfiniteStorageComponent> {

public Map<String, Integer> inventory = Maps.newHashMap();

public InfiniteStorageComponent(int i) {
public InfiniteStorageComponent() {
}

public InfiniteStorageComponent() {}
public InfiniteStorageComponent(int i) {
}

@Override
public void copyFrom(InfiniteStorageComponent other) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.economy.events;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.economy.events;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.economy.events;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.economy.events;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.economy.events;


Expand Down
17 changes: 2 additions & 15 deletions src/main/java/org/terasology/economy/events/ResourceDrawEvent.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.economy.events;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.economy.events;

import org.terasology.engine.entitySystem.event.Event;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.economy.events;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.economy.events;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.economy.events;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.economy.events;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* Handler for currency stores.
*/
public class CurrencyStorageHandler implements StorageComponentHandler<CurrencyStorageComponent> {
private final String CURRENCY = "currency";
private static final Logger logger = LoggerFactory.getLogger(CurrencyStorageHandler.class);

private Logger logger = LoggerFactory.getLogger(CurrencyStorageHandler.class);
private static final String CURRENCY = "currency";

@Override
public int store(CurrencyStorageComponent storage, String resource, int amount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
package org.terasology.economy.handler;


import org.terasology.economy.components.InfiniteStorageComponent;
import org.terasology.gestalt.entitysystem.component.Component;

Expand All @@ -11,7 +10,8 @@

public class InfiniteStorageHandler implements StorageComponentHandler<InfiniteStorageComponent> {

public InfiniteStorageHandler() {}
public InfiniteStorageHandler() { }

@Override
public int store(InfiniteStorageComponent infiniteStorageComponent, String resource, int amount) {
Map<String, Integer> inventory = infiniteStorageComponent.inventory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.terasology.engine.registry.Share;
import org.terasology.engine.utilities.Assets;
import org.terasology.engine.world.block.BlockManager;
import org.terasology.engine.world.block.entity.BlockCommands;
import org.terasology.engine.world.block.family.BlockFamily;
import org.terasology.engine.world.block.items.BlockItemComponent;
import org.terasology.engine.world.block.items.BlockItemFactory;
Expand All @@ -41,23 +40,22 @@
@RegisterSystem(RegisterMode.AUTHORITY)
public class MultiInvStorageHandler extends BaseComponentSystem implements StorageComponentHandler<MultiInvStorageComponent> {

private static final Logger logger = LoggerFactory.getLogger(MultiInvStorageHandler.class);

@In
private AssetManager assetManager;

@In
private EntityManager entityManager;

@In
private BlockCommands blockCommands;

@In
private BlockManager blockManager;

@In
private InventoryManager inventoryManager;

private BlockItemFactory blockItemFactory;
private Logger logger = LoggerFactory.getLogger(MultiInvStorageHandler.class);

private ResourceUrn blockItemBase;

@Override
Expand All @@ -73,55 +71,56 @@ public void postBegin() {
@Override
public int store(MultiInvStorageComponent multiInvStorageComponent, String resource, int amount) {
EntityRef item = getItemEntity(resource);
byte byteAmount;

if (item == EntityRef.NULL) {
return amount;
}




for (EntityRef entityRef : multiInvStorageComponent.chests) {
int amountForChest = getItemCapacityForChest(entityRef, item);
amountForChest = (amountForChest > amount) ? amount : amountForChest;
int remaining = amount;
for (EntityRef chest : multiInvStorageComponent.chests) {
final int amountForChest = Math.min(getItemCapacityForChest(chest, item), remaining);
final byte byteAmount;
if (amountForChest >= Byte.MAX_VALUE) {
byteAmount = Byte.MAX_VALUE;
} else {
byteAmount = (byte) amountForChest;
}

ItemComponent itemComponent = item.getComponent(ItemComponent.class);
itemComponent.stackCount = byteAmount;
item.saveComponent(itemComponent);
inventoryManager.giveItem(entityRef, EntityRef.NULL, item);
amount -= amountForChest;

if (amount == 0) {
inventoryManager.giveItem(chest, EntityRef.NULL, item);

remaining -= byteAmount;

if (remaining == 0) {
return 0;
}
}
return amount;

return remaining;
}

@Override
public int draw(MultiInvStorageComponent multiInvStorageComponent, String resource, int amount) {
EntityRef item = getItemEntity(resource);

for (EntityRef entityRef : multiInvStorageComponent.chests) {
int amountForChest = getItemCountForChest(entityRef, item);
int remaining = amount;
for (EntityRef chest : multiInvStorageComponent.chests) {
int amountForChest = getItemCountForChest(chest, item);
while (amountForChest != 0) {
int slot = getSlotWithItem(entityRef, item);
int slot = getSlotWithItem(chest, item);
if (slot == -1) {
break;
}
int amountForSlot = InventoryUtils.getStackCount(InventoryUtils.getItemAt(entityRef, slot));
if (inventoryManager.removeItem(entityRef, EntityRef.NULL, slot, true, amountForSlot) != null) {
amount -= amountForSlot;
int amountForSlot = InventoryUtils.getStackCount(InventoryUtils.getItemAt(chest, slot));
if (inventoryManager.removeItem(chest, EntityRef.NULL, slot, true, amountForSlot) != null) {
remaining -= amountForSlot;
}
}

}
return amount;
return remaining;
}

@Override
Expand All @@ -137,13 +136,8 @@ public int availableResourceAmount(MultiInvStorageComponent multiInvStorageCompo
@Override
public Set<String> availableResourceTypes(MultiInvStorageComponent multiInvStorageComponent) {
Set<String> result = new HashSet<>();
int amount = 0;
for (EntityRef entityRef : multiInvStorageComponent.chests) {
for (String resource : getResourceTypesOfInventory(entityRef)) {
if (!result.contains(resource)) {
result.add(resource);
}
}
result.addAll(getResourceTypesOfInventory(entityRef));
}
return result;
}
Expand Down Expand Up @@ -256,7 +250,7 @@ private Set<String> getResourceTypesOfInventory(EntityRef entity) {
if (!entity.exists() || !entity.isActive()) {
return set;
}
for(EntityRef item : inventoryComponent.itemSlots) {
for (EntityRef item : inventoryComponent.itemSlots) {
ItemComponent itemComponent = item.getComponent(ItemComponent.class);
if (itemComponent != null && !set.contains(itemComponent.stackId)) {
ResourceUrn uri = item.getParentPrefab().getUrn();
Expand Down
Loading

0 comments on commit 15c30f1

Please sign in to comment.