Skip to content

Commit 1a7af09

Browse files
committed
Added schematic descriptions Finishes #125
Added `cost-modifier` econ config option Updated bStats
1 parent 623ff47 commit 1a7af09

File tree

15 files changed

+202
-77
lines changed

15 files changed

+202
-77
lines changed

.idea/runConfigurations/SpongeForge.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
# Beta 30 - Grief Defender Port
4+
**REQUIRED: Sponge API 7.1 (SF 3682+); Grief Defender 1.12.2-4.3.0.622+; Permissions Plugin (ie. LuckPerms)**
5+
**OPTIONAL: Nucleus 1.9.0-S7.1+**
6+
- Added economy `cost-modifier` config to adjust the currency cost of `/is expand` relative to it's block cost
7+
- Added new schematic features:
8+
- `/is schematic setdescription <schematic> <name>` - set an in-game description for a schematic that supports formatting code & newlines (`/n`)
9+
- Updated bStats to version 1.7
310

411
# Beta 29.1 - Grief Defender Port
512
**REQUIRED: Sponge API 7.1 (SF 3682+); Grief Defender 1.12.2-4.3.0.622+; Permissions Plugin (ie. LuckPerms)**

build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ repositories {
4343
name = "LuckPerms"
4444
url = "https://repo.lucko.me/"
4545
}
46-
maven {
47-
name = "bStats"
48-
url = "http://repo.bstats.org/content/repositories/releases/"
49-
}
5046
maven {
5147
name = "Aikar"
5248
url = "https://repo.aikar.co/content/groups/aikar/"

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
## Version
22
major=0
3-
minor=29
4-
patch=1
3+
minor=30
4+
patch=0
55
api=S7.1
6-
suffix=GRIEF-DEFENDER-PR2
6+
suffix=GRIEF-DEFENDER
77
## Dependencies
88
spongeapi=7.1.0
99
spongeforge=1.12.2-2768-7.1.4
1010
forge=14.23.5.2768
1111
griefdefender=1.0.0
1212
nucleus=1.9.0-S7.1
13-
bstats=1.4
13+
bstats=1.7

src/main/java/net/mohron/skyclaims/SkyClaims.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ public class SkyClaims {
118118
@Inject
119119
private Game game;
120120

121-
@Inject
122121
private Metrics2 metrics;
123122

124123
@Inject
@@ -142,6 +141,11 @@ public class SkyClaims {
142141

143142
private static final String ISLAND_CLEANUP = "skyclaims.island.cleanup";
144143

144+
@Inject
145+
public SkyClaims(Metrics2.Factory metricsFactory) {
146+
metrics = metricsFactory.make(96);
147+
}
148+
145149
public static SkyClaims getInstance() {
146150
return instance;
147151
}

src/main/java/net/mohron/skyclaims/command/CommandBase.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,20 @@ protected void listSchematics(Player player, Function<IslandSchematic, Consumer<
229229

230230
if (PLUGIN.getConfig().getMiscConfig().isTextSchematicList()) {
231231
List<Text> schematicText = schematics.stream()
232-
.map(s -> s.getText().toBuilder().onClick(TextActions.executeCallback(mapper.apply(s))).build())
232+
.map(s -> s.getText().toBuilder()
233+
.onHover(TextActions.showItem(s.getItemStackRepresentation().createSnapshot()))
234+
.onClick(TextActions.executeCallback(mapper.apply(s)))
235+
.build())
233236
.collect(Collectors.toList());
234237

235238
PaginationList.builder()
236239
.title(Text.of(TextColors.AQUA, "Schematics"))
237240
.padding(Text.of(TextColors.AQUA, TextStyles.STRIKETHROUGH, "-"))
238241
.contents(schematicText)
239242
.sendTo(player);
243+
} else {
244+
player.openInventory(SchematicUI.of(schematics, mapper));
240245
}
241-
242-
player.openInventory(SchematicUI.of(schematics, mapper));
243246
}
244247

245248
protected void clearIslandMemberInventories(Island island, String keepPlayerInv, String keepEnderChestInv) {

src/main/java/net/mohron/skyclaims/command/schematic/CommandSchematic.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static void register() {
4545
.child(CommandSchematicInfo.commandSpec, "info")
4646
.child(CommandSchematicList.commandSpec, "list")
4747
.child(CommandSchematicSetBiome.commandSpec, "setbiome")
48+
.child(CommandSchematicSetDescription.commandSpec, "setdescription")
4849
.child(CommandSchematicSetHeight.commandSpec, "setheight")
4950
.child(CommandSchematicSetIcon.commandSpec, "seticon")
5051
.child(CommandSchematicSetName.commandSpec, "setname")
@@ -70,6 +71,7 @@ private static void registerSubCommands() {
7071
CommandSchematicInfo.register();
7172
CommandSchematicList.register();
7273
CommandSchematicSetBiome.register();
74+
CommandSchematicSetDescription.register();
7375
CommandSchematicSetHeight.register();
7476
CommandSchematicSetIcon.register();
7577
CommandSchematicSetName.register();

src/main/java/net/mohron/skyclaims/command/schematic/CommandSchematicInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ private List<Text> getDetails(IslandSchematic schematic) {
113113
contents.add(Text.of(TextColors.YELLOW, "Author", TextColors.WHITE, " : ", TextColors.GRAY, schematic.getAuthor()));
114114
contents.add(Text.of(TextColors.YELLOW, "Date", TextColors.WHITE, " : ", TextColors.GRAY, schematic.getDate()));
115115
contents.add(Text.of(TextColors.YELLOW, "Filename", TextColors.WHITE, " : ", TextColors.GRAY, schematic.getName()));
116+
contents.add(Text.of(TextColors.YELLOW, "Description", TextColors.WHITE, " : ", TextColors.GRAY, schematic.getDescriptionText()));
116117
contents.add(Text.of(TextColors.YELLOW, "Biome", TextColors.WHITE, " : ", TextColors.GRAY, schematic.getBiomeType().map(CatalogType::getName).orElse("none")));
117118
contents.add(Text.of(TextColors.YELLOW, "Height", TextColors.WHITE, " : ", TextColors.LIGHT_PURPLE, schematic.getHeight().map(Text::of).orElse(NONE)));
118119
contents.add(Text.of(TextColors.YELLOW, "Icon", TextColors.WHITE, " : ", TextColors.GRAY, schematic.getIcon().map(i -> Text.of(i).toText()).orElse(NONE)));
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* SkyClaims - A Skyblock plugin made for Sponge
3+
* Copyright (C) 2017 Mohron
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* SkyClaims is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with SkyClaims. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package net.mohron.skyclaims.command.schematic;
20+
21+
import net.mohron.skyclaims.command.CommandBase;
22+
import net.mohron.skyclaims.command.argument.Arguments;
23+
import net.mohron.skyclaims.permissions.Permissions;
24+
import net.mohron.skyclaims.schematic.IslandSchematic;
25+
import org.spongepowered.api.command.CommandException;
26+
import org.spongepowered.api.command.CommandResult;
27+
import org.spongepowered.api.command.CommandSource;
28+
import org.spongepowered.api.command.args.CommandContext;
29+
import org.spongepowered.api.command.args.GenericArguments;
30+
import org.spongepowered.api.command.spec.CommandSpec;
31+
import org.spongepowered.api.text.Text;
32+
import org.spongepowered.api.text.format.TextColors;
33+
34+
public class CommandSchematicSetDescription extends CommandBase {
35+
36+
public static final String HELP_TEXT = "used to set the name for a schematic";
37+
private static final Text SCHEMATIC = Text.of("schematic");
38+
private static final Text DESCRIPTION = Text.of("description");
39+
40+
public static CommandSpec commandSpec = CommandSpec.builder()
41+
.permission(Permissions.COMMAND_SCHEMATIC_SET_NAME)
42+
.description(Text.of(HELP_TEXT))
43+
.arguments(
44+
Arguments.schematic(SCHEMATIC),
45+
GenericArguments.optional(GenericArguments.remainingRawJoinedStrings(DESCRIPTION))
46+
)
47+
.executor(new CommandSchematicSetDescription())
48+
.build();
49+
50+
public static void register() {
51+
try {
52+
PLUGIN.getGame().getCommandManager().register(PLUGIN, commandSpec);
53+
PLUGIN.getLogger().debug("Registered command: CommandSchematicSetDescription");
54+
} catch (UnsupportedOperationException e) {
55+
PLUGIN.getLogger().error("Failed to register command: CommandSchematicSetDescription", e);
56+
}
57+
}
58+
59+
@Override
60+
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
61+
IslandSchematic schematic = args.<IslandSchematic>getOne(SCHEMATIC)
62+
.orElseThrow(() -> new CommandException(Text.of(TextColors.RED, "You must provide a schematic to use this command!")));
63+
String description = args.<String>getOne(DESCRIPTION).orElse(null);
64+
65+
if (description != null) {
66+
schematic.setDescription(description.replace("\\n", "\n"));
67+
} else {
68+
schematic.setDescription(null);
69+
}
70+
71+
if (PLUGIN.getSchematicManager().save(schematic)) {
72+
src.sendMessage(Text.of(
73+
TextColors.GREEN, "Successfully updated schematic description to", TextColors.WHITE, ":", Text.NEW_LINE,
74+
TextColors.RESET, schematic.getDescriptionText()
75+
));
76+
return CommandResult.success();
77+
} else {
78+
throw new CommandException(Text.of(TextColors.RED, "Failed to update schematic."));
79+
}
80+
}
81+
}

src/main/java/net/mohron/skyclaims/command/user/CommandExpand.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private Consumer<CommandSource> expandIsland(Island island, Claim claim, int blo
138138
));
139139
return;
140140
}
141-
int cost = getCost(blocks, claim);
141+
double cost = getCost(blocks, claim);
142142

143143
// Attempt to charge the required currency to the island owner.
144144
if (charge(island, cost)) {
@@ -170,12 +170,14 @@ private boolean exceedsMaxSize(Island island, Claim claim, int blocks) {
170170
return claim.getWidth() + blocks * 2 > Options.getMaxSize(island.getOwnerUniqueId()) * 2;
171171
}
172172

173-
private int getCost(int blocks, Claim claim) {
174-
return (int) Math.pow(claim.getWidth() + blocks, 2)
175-
* (GriefDefender.getCore().getClaimBlockSystem() == ClaimBlockSystem.VOLUME ? 256 : 1) - claim.getClaimBlocks();
173+
private double getCost(int blocks, Claim claim) {
174+
final int claimSystemModifier = GriefDefender.getCore().getClaimBlockSystem() == ClaimBlockSystem.VOLUME ? 256 : 1;
175+
final double newBlocks = Math.pow(claim.getWidth() + blocks, 2) * claimSystemModifier - claim.getClaimBlocks();
176+
177+
return Math.round(newBlocks * PLUGIN.getConfig().getEconomyConfig().getCostModifier() * 100) / 100.0;
176178
}
177179

178-
private boolean charge(Island island, int cost) {
180+
private boolean charge(Island island, double cost) {
179181
EconomyConfig config = PLUGIN.getConfig().getEconomyConfig();
180182
Optional<EconomyService> economyService = Sponge.getServiceManager().provide(EconomyService.class);
181183

@@ -200,7 +202,7 @@ private boolean charge(Island island, int cost) {
200202
if (data.isPresent()) {
201203
if (data.get().getRemainingClaimBlocks() >= cost) {
202204
// Use the Owner's claim blocks to expand the island
203-
data.get().setBonusClaimBlocks(data.get().getBonusClaimBlocks() - cost);
205+
data.get().setBonusClaimBlocks(data.get().getBonusClaimBlocks() - (int) Math.round(cost));
204206
return true;
205207
}
206208
return false;

0 commit comments

Comments
 (0)