Skip to content

Commit cc7df2d

Browse files
authored
Merge pull request #3 from BentoBoxWorld/code_clean_up
Add unclaim command
2 parents dbdbab5 + 1256c4c commit cc7df2d

File tree

10 files changed

+147
-19
lines changed

10 files changed

+147
-19
lines changed

src/main/java/world/bentobox/stranger/Settings.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import world.bentobox.bentobox.database.objects.adapters.Adapter;
2323
import world.bentobox.bentobox.database.objects.adapters.FlagSerializer;
2424
import world.bentobox.bentobox.database.objects.adapters.FlagSerializer2;
25+
import world.bentobox.stranger.border.BorderType;
2526

2627
/**
2728
* All the plugin settings are here
@@ -60,9 +61,9 @@ public class Settings implements WorldSettings {
6061
private String friendlyName = "StrangerRealms";
6162

6263
@ConfigComment("Name of the world - if it does not exist then it will be generated.")
63-
@ConfigComment("It acts like a prefix for nether and end (e.g. stranger_world, stranger_world_nether, stranger_world_end)")
64+
@ConfigComment("It acts like a prefix for nether and end (e.g. stranger-world, stranger-world_nether, stranger-world_end)")
6465
@ConfigEntry(path = "world.world-name")
65-
private String worldName = "stranger_world";
66+
private String worldName = "stranger-world";
6667

6768
@ConfigComment("World seed.")
6869
@ConfigEntry(path = "world.generator.seed", needsReset = true)

src/main/java/world/bentobox/stranger/StrangerRealms.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Collections;
55
import java.util.EnumSet;
66
import java.util.List;
7+
import java.util.Map;
78
import java.util.Set;
89

910
import org.bukkit.Bukkit;
@@ -19,7 +20,6 @@
1920
import org.bukkit.inventory.meta.ItemMeta;
2021
import org.bukkit.scheduler.BukkitTask;
2122
import org.eclipse.jdt.annotation.Nullable;
22-
import org.jetbrains.annotations.NotNull;
2323

2424
import net.kyori.adventure.text.Component;
2525
import net.kyori.adventure.text.format.NamedTextColor;
@@ -31,9 +31,14 @@
3131
import world.bentobox.bentobox.api.configuration.WorldSettings;
3232
import world.bentobox.bentobox.database.objects.Island;
3333
import world.bentobox.bentobox.managers.IslandsManager;
34+
import world.bentobox.stranger.border.BorderType;
35+
import world.bentobox.stranger.border.PerPlayerBorderProxy;
36+
import world.bentobox.stranger.border.ShowBarrier;
37+
import world.bentobox.stranger.border.ShowWorldBorder;
3438
import world.bentobox.stranger.commands.admin.WorldBorderCommand;
3539
import world.bentobox.stranger.commands.player.ClaimCommand;
3640
import world.bentobox.stranger.commands.player.SpawnCommand;
41+
import world.bentobox.stranger.commands.player.UnclaimCommand;
3742
import world.bentobox.stranger.generator.NetherBiomeProvider;
3843
import world.bentobox.stranger.generator.NetherChunks;
3944
import world.bentobox.stranger.listeners.BorderShower;
@@ -93,6 +98,7 @@ public void setup()
9398
super.setup();
9499
// Commands
95100
new ClaimCommand(this);
101+
new UnclaimCommand(this);
96102
new SpawnCommand(this);
97103
}
98104
};
@@ -145,6 +151,7 @@ public void onEnable() {
145151
Island spawn = getPlugin().getIslands().createIsland(getOverWorld().getSpawnLocation());
146152
if (spawn != null) {
147153
spawn.setSpawn(true);
154+
spawn.setSpawnPoint(Map.of(Environment.NORMAL, getOverWorld().getSpawnLocation()));
148155
IslandsManager.saveIsland(spawn);
149156
} else {
150157
this.logError("Could not make a spawn claim. You will have to set one manually in the world.");

src/main/java/world/bentobox/stranger/BorderType.java renamed to src/main/java/world/bentobox/stranger/border/BorderType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package world.bentobox.stranger;
1+
package world.bentobox.stranger.border;
22

33
import java.util.Optional;
44

src/main/java/world/bentobox/stranger/PerPlayerBorderProxy.java renamed to src/main/java/world/bentobox/stranger/border/PerPlayerBorderProxy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package world.bentobox.stranger;
1+
package world.bentobox.stranger.border;
22

33
import org.bukkit.entity.Player;
44

55
import world.bentobox.bentobox.api.user.User;
6+
import world.bentobox.stranger.StrangerRealms;
67
import world.bentobox.stranger.listeners.BorderShower;
78

89
public final class PerPlayerBorderProxy implements BorderShower {

src/main/java/world/bentobox/stranger/ShowBarrier.java renamed to src/main/java/world/bentobox/stranger/border/ShowBarrier.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package world.bentobox.stranger;
1+
package world.bentobox.stranger.border;
22

33
import java.util.HashMap;
44
import java.util.HashSet;
@@ -22,6 +22,7 @@
2222
import world.bentobox.bentobox.api.metadata.MetaDataValue;
2323
import world.bentobox.bentobox.api.user.User;
2424
import world.bentobox.bentobox.util.Util;
25+
import world.bentobox.stranger.StrangerRealms;
2526
import world.bentobox.stranger.listeners.BorderShower;
2627

2728
/**

src/main/java/world/bentobox/stranger/ShowWorldBorder.java renamed to src/main/java/world/bentobox/stranger/border/ShowWorldBorder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package world.bentobox.stranger;
1+
package world.bentobox.stranger.border;
22

33
import java.util.Objects;
44

@@ -14,6 +14,7 @@
1414
import world.bentobox.bentobox.api.user.User;
1515
import world.bentobox.bentobox.util.Util;
1616
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
17+
import world.bentobox.stranger.StrangerRealms;
1718
import world.bentobox.stranger.listeners.BorderShower;
1819

1920
/**

src/main/java/world/bentobox/stranger/commands/player/ClaimCommand.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public void setup() {
7070
*/
7171
@Override
7272
public boolean canExecute(User user, String label, List<String> args) {
73+
// Check if the player is in a claim
74+
if (getIslands().getIslandAt(user.getLocation()).isPresent()) {
75+
user.sendMessage("strangerrealms.errors.already-claimed");
76+
return false;
77+
}
7378
// Check if the island is reserved
7479
@Nullable
7580
Island island = getIslands().getPrimaryIsland(getWorld(), user.getUniqueId());
@@ -131,7 +136,9 @@ public boolean execute(User user, String label, List<String> args) {
131136
private boolean makeClaim(User user, String name) {
132137
user.sendMessage("commands.island.create.creating-island");
133138
try {
134-
NewIsland.builder().player(user).addon(getAddon()).reason(Reason.CREATE).name(name).locationStrategy(strategy).noPaste().build();
139+
NewIsland.builder().player(user).addon(getAddon()).reason(Reason.CREATE)
140+
.name(name).locationStrategy(strategy)
141+
.noPaste().build();
135142
} catch (IOException e) {
136143
user.sendMessage(e.getMessage());
137144
return false;
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package world.bentobox.stranger.commands.player;
2+
3+
import java.util.List;
4+
import java.util.Optional;
5+
import java.util.UUID;
6+
7+
import org.bukkit.entity.Player;
8+
9+
import world.bentobox.bentobox.api.commands.CompositeCommand;
10+
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
11+
import world.bentobox.bentobox.api.events.IslandBaseEvent;
12+
import world.bentobox.bentobox.api.events.island.IslandEvent;
13+
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
14+
import world.bentobox.bentobox.api.user.User;
15+
import world.bentobox.bentobox.database.objects.Island;
16+
import world.bentobox.bentobox.database.objects.IslandDeletion;
17+
import world.bentobox.stranger.StrangerRealms;
18+
19+
/**
20+
* Handles removing a claim
21+
*
22+
* @author tastybento
23+
*/
24+
public class UnclaimCommand extends ConfirmableCommand {
25+
26+
private StrangerRealms addon;
27+
/**
28+
* Command to create a claim
29+
*
30+
* @param playerCommand - parent command
31+
*/
32+
public UnclaimCommand(CompositeCommand playerCommand) {
33+
super(playerCommand, "unclaim");
34+
}
35+
36+
@Override
37+
public void setup() {
38+
setPermission("unclaim");
39+
setOnlyPlayer(true);
40+
setDescription("commands.unclaim.description");
41+
addon = (StrangerRealms)getAddon();
42+
}
43+
44+
/**
45+
* Checks if the command can be executed by this user.
46+
*/
47+
@Override
48+
public boolean execute(User user, String label, List<String> args) {
49+
// If args are not right, show help
50+
if (!args.isEmpty()) {
51+
showHelp(this, user);
52+
return false;
53+
}
54+
if (!getIslands().hasIsland(getWorld(), user)) {
55+
user.sendMessage("general.errors.no-island");
56+
return false;
57+
}
58+
// Check if the player is in a claim
59+
Optional<Island> opClaim = getIslands().getIslandAt(user.getLocation())
60+
.filter(is -> ((StrangerRealms)getAddon()).inWorld(is.getWorld()))
61+
.filter(is -> is.getOwner() != null && is.getOwner().equals(user.getUniqueId()));
62+
if (opClaim.isEmpty()) {
63+
user.sendMessage("strangerrealms.errors.must-be-in");
64+
return false;
65+
}
66+
askConfirmation(user, () -> deleteClaim(user,opClaim.get() ));
67+
return true;
68+
}
69+
70+
/**
71+
* Handles the unclaim creation process.
72+
* There isn't a neat way to do this through IslandsManager so it has to be done manually
73+
*/
74+
public boolean deleteClaim(User user, Island claim) {
75+
UUID uuid = user.getUniqueId();
76+
// Fire preclear event
77+
IslandEvent.builder().involvedPlayer(uuid).reason(Reason.PRECLEAR).island(claim)
78+
.oldIsland(claim).location(claim.getCenter()).build();
79+
// Fire delete event
80+
IslandBaseEvent event = IslandEvent.builder().island(claim).involvedPlayer(uuid)
81+
.reason(Reason.DELETE).build();
82+
if (event.getNewEvent().map(IslandBaseEvent::isCancelled).orElse(event.isCancelled())) {
83+
return false;
84+
}
85+
// Get a list of any players in the claim
86+
List<Player> players = claim.getPlayersOnIsland();
87+
// Set the owner of the island to no one.
88+
claim.setOwner(null);
89+
// Remove players from island
90+
getIslands().removePlayersFromIsland(claim);
91+
// Mark island as deletable
92+
claim.setDeletable(true);
93+
// Remove island from the cache
94+
getIslands().getIslandCache().deleteIslandFromCache(claim);
95+
// Delete the island from the database
96+
getIslands().deleteIslandId(claim.getUniqueId());
97+
// Fire the deletion event immediately
98+
IslandEvent.builder().deletedIslandInfo(new IslandDeletion(claim)).reason(Reason.DELETED).build();
99+
// Tell user
100+
user.sendMessage("strangerrealms.commands.unclaim.success");
101+
// Refresh borders
102+
players.forEach(p -> addon.getBorderShower().showBorder(p));
103+
return true;
104+
}
105+
106+
}

src/main/resources/config.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,17 @@ world:
227227
FROST_WALKER: 200
228228
LEAF_DECAY: 200
229229
COLLECT_LAVA: 200
230-
ENDERMAN_TELEPORT: 200
230+
ENDERMAN_TELEPORT: 500
231231
LEVER: 200
232-
HURT_MONSTERS: 200
232+
HURT_MONSTERS: 0
233233
CAKE: 200
234-
FIRE_SPREAD: 200
234+
FIRE_SPREAD: 500
235235
CHANGE_SETTINGS: 1000
236236
SIGN_EDITING: 200
237237
TRADING: 200
238238
EGGS: 200
239239
CHEST: 200
240-
TNT_DAMAGE: 200
240+
TNT_DAMAGE: 500
241241
FLINT_AND_STEEL: 200
242242
SCULK_SENSOR: 200
243243
CROP_TRAMPLE: 200
@@ -262,7 +262,7 @@ world:
262262
ANIMAL_SPAWNERS_SPAWN: 200
263263
ENCHANTING: 200
264264
BLOCK_EXPLODE_DAMAGE: 200
265-
BOAT: 200
265+
BOAT: 0
266266
BED: 200
267267
SPAWN_EGGS: 200
268268
MONSTER_NATURAL_SPAWN: 200
@@ -287,26 +287,26 @@ world:
287287
FURNACE: 200
288288
MONSTER_SPAWNERS_SPAWN: 200
289289
MINECART: 200
290-
FIRE_IGNITE: 200
290+
FIRE_IGNITE: 1
291291
FISH_SCOOPING: 200
292292
END_PORTAL: 200
293293
BREEDING: 200
294294
HURT_VILLAGERS: 200
295295
TURTLE_EGGS: 200
296296
BREAK_SPAWNERS: 200
297-
RIDING: 200
297+
RIDING: 0
298298
ARMOR_STAND: 200
299299
NAME_TAG: 200
300-
ITEM_DROP: 200
300+
ITEM_DROP: 0
301301
NOTE_BLOCK: 200
302302
NETHER_PORTAL: 200
303303
LECTERN: 200
304304
GRINDSTONE: 200
305305
SHULKER_BOX: 200
306-
ITEM_PICKUP: 200
306+
ITEM_PICKUP: 0
307307
BREWING: 200
308308
STONECUTTING: 200
309-
FIRE_EXTINGUISH: 200
309+
FIRE_EXTINGUISH: 0
310310
BEACON: 200
311311
ALLAY: 200
312312
PRESSURE_PLATE: 200

src/main/resources/locales/en-US.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ strangerrealms:
1111
Islands: Claims
1212
teleporting-to-spawn: "&c You were outside the border. Teleported to spawn.."
1313
errors:
14-
not-in-world: "&c You must be in the world to claim"
14+
not-in-world: "&c You must be in the world to claim."
1515
already-claimed: "&c This location is already claimed!"
16+
must-be-in: "&c You must be in your claim to do that."
1617
overlap: "&c You cannot make a claim here because it would overlap another claim
1718
at [xyz]."
1819
too-close-to-spawn: "&c You are too close to spawn to make a claim. Move further out."
@@ -36,6 +37,9 @@ strangerrealms:
3637
needs-value: "&c Set needs an integer value for the size of the world border"
3738
claim:
3839
description: "Attemtps to make a claim"
40+
unclaim:
41+
description: "Removes a claim"
42+
success: "&a Your claim was removed successfully"
3943
island:
4044
create:
4145
creating-island: "&a Trying to claim..."

0 commit comments

Comments
 (0)