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

Make plot groups extend townyobject #7141

Merged
merged 2 commits into from
Jan 3, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private static List<String> getPlotGroupColumns() {
columns.add("`groupName` mediumtext NOT NULL");
columns.add("`groupPrice` float DEFAULT NULL");
columns.add("`town` VARCHAR(32) NOT NULL");
columns.add("`metadata` text DEFAULT NULL");
return columns;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,10 @@ public boolean loadPlotGroup(PlotGroup group) {
line = keys.get("groupPrice");
if (line != null && !line.isEmpty())
group.setPrice(Double.parseDouble(line.trim()));

line = keys.get("metadata");
if (line != null)
MetadataLoader.getInstance().deserializeMetadata(group, line.trim());

} catch (Exception e) {
TownyMessaging.sendErrorMsg(Translation.of("flatfile_err_exception_reading_group_file_at_line", path, line));
Expand Down Expand Up @@ -2081,6 +2085,7 @@ public boolean savePlotGroup(PlotGroup group) {
list.add("groupName=" + group.getName());
list.add("groupPrice=" + group.getPrice());
list.add("town=" + group.getTown().getName());
list.add("metadata=" + serializeMetadata(group));
} catch (Exception e) {
logger.warn("An exception occurred while saving plot group " + Optional.ofNullable(group).map(g -> g.getUUID().toString()).orElse("null") + ": ", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,11 @@ private boolean loadPlotGroup(ResultSet rs) {
group.setPrice(Float.parseFloat(line.trim()));
} catch (Exception ignored) {}
}

line = rs.getString("metadata");
if (line != null) {
MetadataLoader.getInstance().deserializeMetadata(group, line);
}
} catch (SQLException e) {
plugin.getLogger().log(Level.WARNING, "Loading Error: Exception while reading plot group: " + uuid
+ " at line: " + line + " in the sql database", e);
Expand Down Expand Up @@ -2267,6 +2272,7 @@ public synchronized boolean savePlotGroup(PlotGroup group) {
pltgrp_hm.put("groupName", group.getName());
pltgrp_hm.put("groupPrice", group.getPrice());
pltgrp_hm.put("town", group.getTown().getName());
pltgrp_hm.put("metadata", serializeMetadata(group));

updateDB("PLOTGROUPS", pltgrp_hm, Collections.singletonList("groupID"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
*
* @author Suneet Tipirneni (Siris)
*/
public abstract class ObjectGroup implements Nameable, Identifiable {
public abstract class ObjectGroup extends TownyObject implements Identifiable {
private UUID uuid;
private String name;

/**
* The constructor for the Group object.
* @param id A unique identifier for the group id.
* @param name An alias for the id used for player in-game interaction via commands.
*/
public ObjectGroup(UUID id, String name) {
this.uuid = id;
this.name = name;
super(name);
this.uuid = id;
}

public UUID getUUID() {
Expand All @@ -28,13 +27,6 @@ public UUID getUUID() {
public void setUUID(UUID id) {
this.uuid = id;
}

@Override
public String getName() {
return name;
}

public void setName(String name) { this.name = name; }

/**
* Determines whether a group is equivalent or not.
Expand All @@ -56,7 +48,7 @@ public boolean equals(Object obj) {
*/
@Override
public String toString() {
return name + "," + uuid;
return getName() + "," + uuid;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public String toString() {
return super.toString() + "," + getTown().toString() + "," + getPrice();
}

@Override
public boolean exists() {
return this.town != null && this.town.exists() && this.town.hasPlotGroupName(getName());
}

/**
* Override the name change method to internally rehash the plot group map.
* @param name The name of the group.
Expand Down