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

Removed unused (de)serialization methodes #147

Open
wants to merge 6 commits into
base: 2.6.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Replace `[ ]` with `[x]` to cross the checkbox.
- [ ] I have checked the PRs for upcoming features/bug fixes.
- [ ] I have read the [contributing guidelines][contributing].

> It is sometimes better to include more changes in a single commit.
> It is sometimes better to include more _related_ changes in a single commit.
If you find yourself having an overwhelming amount of commits, you
can **rebase** your branch.

Expand Down
14 changes: 1 addition & 13 deletions src/main/java/org/shanerx/tradeshop/item/ShopItemStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class ShopItemStack implements Serializable, Cloneable {
public class ShopItemStack implements Cloneable {

@Expose
private ItemStack itemStack;
Expand Down Expand Up @@ -124,17 +123,6 @@ public Map<ShopItemStackSettingKeys, ObjectHolder<?>> getItemSettings() {
return itemSettings;
}

public static ShopItemStack deserialize(String serialized) {
ShopItemStack item = new GsonProcessor().fromJson(serialized, ShopItemStack.class);
item.loadLegacyData();
item.buildMap();
return item;
}

public String serialize() {
return new GsonProcessor().toJson(this);
}

Comment on lines -127 to -137
Copy link
Collaborator

Choose a reason for hiding this comment

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

Removing Serializable is good if it's not being used, but I see no point in removing the (de)serialize methods since at worst they just waste space. They do occasionally get used when I need to add debug to a section. In most cases when I do that they have to be removed soon after for performance like in the Hopper code(where no debug can stay since it runs so often with each hopper)

public ObjectHolder<?> getShopSetting(ShopItemStackSettingKeys key) {
if (key.isUserEditable() && itemSettings.containsKey(key)) {
ObjectHolder<?> tempObj = itemSettings.get(key);
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/org/shanerx/tradeshop/player/PlayerSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@
import org.shanerx.tradeshop.utils.Utils;
import org.shanerx.tradeshop.utils.gsonprocessing.GsonProcessor;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public class PlayerSetting implements Serializable {
public class PlayerSetting {

private transient UUID uuid;
private final String uuidString;
Expand Down Expand Up @@ -80,12 +79,6 @@ public PlayerSetting(UUID playerUUID) {
load();
}

public static PlayerSetting deserialize(String serialized) {
PlayerSetting playerSetting = new GsonProcessor().fromJson(serialized, PlayerSetting.class);
playerSetting.load();
return playerSetting;
}

Comment on lines -83 to -88
Copy link
Collaborator

Choose a reason for hiding this comment

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

^

public boolean isAdminEnabled() {
return adminEnabled;
}
Expand Down Expand Up @@ -147,10 +140,6 @@ public void load() {
utils = new Utils();
}

public String serialize() {
return new GsonProcessor().toJson(this);
}

Comment on lines -150 to -153
Copy link
Collaborator

Choose a reason for hiding this comment

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

^

public String getInvolvedStatusesString() {
Set<String> nullShops = new HashSet<>();
StringBuilder sb = new StringBuilder();
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/org/shanerx/tradeshop/player/ShopUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
import org.bukkit.inventory.meta.SkullMeta;
import org.shanerx.tradeshop.utils.gsonprocessing.GsonProcessor;

import java.io.Serializable;
import java.util.UUID;

@SuppressWarnings("unused")
public class ShopUser implements Serializable {
public class ShopUser {

private transient OfflinePlayer player;
@SerializedName("player")
Expand All @@ -56,12 +55,6 @@ public ShopUser(UUID pUUID, ShopRole role) {
this.role = role;
}

public static ShopUser deserialize(String serialized) {
ShopUser shopUser = new GsonProcessor().fromJson(serialized, ShopUser.class);
shopUser.player = Bukkit.getOfflinePlayer(UUID.fromString(shopUser.playerUUID));
return shopUser;
}

Comment on lines -59 to -64
Copy link
Collaborator

Choose a reason for hiding this comment

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

^

public OfflinePlayer getPlayer() {
fix();
return player;
Expand All @@ -85,10 +78,6 @@ private void fix() {
}
}

public String serialize() {
return new GsonProcessor().toJson(this);
}

Comment on lines -88 to -91
Copy link
Collaborator

Choose a reason for hiding this comment

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

^

public ItemStack getHead() {
ItemStack userHead = new ItemStack(Material.PLAYER_HEAD);
SkullMeta userMeta = (SkullMeta) userHead.getItemMeta();
Expand Down
25 changes: 1 addition & 24 deletions src/main/java/org/shanerx/tradeshop/shop/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.shanerx.tradeshop.utils.objects.ObjectHolder;
import org.shanerx.tradeshop.utils.objects.Tuple;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -61,7 +60,7 @@
import java.util.UUID;
import java.util.stream.Collectors;

public class Shop implements Serializable {
public class Shop {

private ShopUser owner;
private Set<UUID> managers, members;
Expand Down Expand Up @@ -146,20 +145,7 @@ public Shop(Location location, ShopType shopType, ShopUser owner) {
}

/**
* Deserializes the object to Json using Gson
*
* @param serialized Shop GSON to be deserialized
*
* @return Shop object from file
*/
public static Shop deserialize(String serialized) {
Shop shop = new GsonProcessor().fromJson(serialized, Shop.class);
shop.fixAfterLoad();

return shop;
}

/**
Comment on lines -149 to -162
Copy link
Collaborator

Choose a reason for hiding this comment

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

^

* Loads a shop from file and returns the Shop object
*
* @param loc Location of the shop sign
Expand Down Expand Up @@ -260,15 +246,6 @@ public int getAvailableTrades() {
return availableTrades;
}

/**
* Serializes the object to Json using Gson
*
* @return serialized string
*/
public String serialize() {
return new GsonProcessor().toJson(this);
}

Comment on lines -263 to -271
Copy link
Collaborator

Choose a reason for hiding this comment

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

^

/**
* Returns the shop signs location as a ShopLocation
*
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/org/shanerx/tradeshop/shop/ShopType.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@
import org.shanerx.tradeshop.player.Permissions;
import org.shanerx.tradeshop.utils.gsonprocessing.GsonProcessor;

import java.io.Serializable;


public enum ShopType implements Serializable {
public enum ShopType {

TRADE(Permissions.CREATE),

Expand Down Expand Up @@ -82,10 +80,6 @@ public static ShopType getType(Sign s) {
return null;
}

public static ShopType deserialize(String serialized) {
return new GsonProcessor().fromJson(serialized, ShopType.class);
}

Comment on lines -85 to -88
Copy link
Collaborator

Choose a reason for hiding this comment

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

^

@Override
public String toString() {
return getKey().getString();
Expand All @@ -105,10 +99,6 @@ public boolean checkPerm(Player pl) {
return Permissions.hasPermission(pl, perm);
}

public String serialize() {
return new GsonProcessor().toJson(this);
}

Comment on lines -108 to -111
Copy link
Collaborator

Choose a reason for hiding this comment

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

^

public boolean isTrade() {
return this.equals(TRADE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import java.io.Serializable;

public class ShopChunk implements Serializable {
public class ShopChunk {

final private String div = ";;";
private final World world;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import java.io.Serializable;

public class ShopLocation implements Serializable {
public class ShopLocation {

final private String div = "::";
private transient World world;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/shanerx/tradeshop/utils/objects/Tuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import com.google.gson.annotations.SerializedName;
import org.shanerx.tradeshop.utils.gsonprocessing.GsonProcessor;

import java.io.Serializable;

public class Tuple<L, R> implements Serializable {
public class Tuple<L, R> {

@SerializedName("right")
private R r;
Expand Down