Skip to content

Commit e47a6ac

Browse files
committed
1.0.7
1 parent 72b5118 commit e47a6ac

File tree

11 files changed

+207
-48
lines changed

11 files changed

+207
-48
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = 'plazmer'
7-
version = '1.0.6'
7+
version = '1.0.7'
88

99
repositories {
1010
mavenCentral()

src/main/java/t/me/p1azmer/plugin/protectionblocks/Perms.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ public class Perms {
1818
public static final JPermission COMMAND_DEPOSIT = new JPermission(PREFIX_COMMAND + "deposit", "Access to the 'deposit' sub-command.");
1919
public static final JPermission COMMAND_DEPOSIT_OTHER = new JPermission(PREFIX_COMMAND + "deposit.other", "Access to the 'deposit other' sub-command.");
2020

21+
public static final JPermission COMMAND_TELEPORT = new JPermission(PREFIX_COMMAND + "teleport", "Access to the 'teleport' sub-command.");
22+
public static final JPermission COMMAND_MENU = new JPermission(PREFIX_COMMAND + "menu", "Access to the 'menu' sub-command.");
23+
2124
public static final JPermission BYPASS_REGION_MANIPULATION = new JPermission(PREFIX_BYPASS + "region.manipulation", "Access to the manipulation in regions");
2225

2326
static {
2427
PLUGIN.addChildren(COMMAND, BYPASS);
2528

2629
COMMAND.addChildren(COMMAND_RELOAD, COMMAND_EDITOR, COMMAND_GIVE,
27-
COMMAND_DEPOSIT, COMMAND_DEPOSIT_OTHER);
30+
COMMAND_DEPOSIT, COMMAND_DEPOSIT_OTHER, COMMAND_TELEPORT, COMMAND_MENU);
2831

2932
BYPASS.addChildren(BYPASS_REGION_MANIPULATION);
3033
}

src/main/java/t/me/p1azmer/plugin/protectionblocks/ProtectionPlugin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import t.me.p1azmer.plugin.protectionblocks.api.integration.HologramHandler;
1111
import t.me.p1azmer.plugin.protectionblocks.commands.EditorCommand;
1212
import t.me.p1azmer.plugin.protectionblocks.commands.GiveCommand;
13+
import t.me.p1azmer.plugin.protectionblocks.commands.MenuCommand;
14+
import t.me.p1azmer.plugin.protectionblocks.commands.TeleportCommand;
1315
import t.me.p1azmer.plugin.protectionblocks.config.Config;
1416
import t.me.p1azmer.plugin.protectionblocks.config.Lang;
1517
import t.me.p1azmer.plugin.protectionblocks.currency.CurrencyManager;
@@ -104,6 +106,8 @@ public void registerCommands(@NotNull GeneralCommand<ProtectionPlugin> generalCo
104106
generalCommand.addChildren(new ReloadSubCommand<>(this, Perms.COMMAND_RELOAD));
105107
generalCommand.addChildren(new EditorCommand(this));
106108
generalCommand.addChildren(new GiveCommand(this));
109+
generalCommand.addChildren(new TeleportCommand(this));
110+
generalCommand.addChildren(new MenuCommand(this));
107111
}
108112

109113
@Override
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package t.me.p1azmer.plugin.protectionblocks.commands;
2+
3+
import org.bukkit.command.CommandSender;
4+
import org.bukkit.entity.Player;
5+
import org.jetbrains.annotations.NotNull;
6+
import t.me.p1azmer.engine.api.command.AbstractCommand;
7+
import t.me.p1azmer.engine.api.command.CommandResult;
8+
import t.me.p1azmer.plugin.protectionblocks.Perms;
9+
import t.me.p1azmer.plugin.protectionblocks.Placeholders;
10+
import t.me.p1azmer.plugin.protectionblocks.ProtectionPlugin;
11+
import t.me.p1azmer.plugin.protectionblocks.config.Lang;
12+
import t.me.p1azmer.plugin.protectionblocks.data.impl.RegionUser;
13+
import t.me.p1azmer.plugin.protectionblocks.region.impl.Region;
14+
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
18+
public class MenuCommand extends AbstractCommand<ProtectionPlugin> {
19+
public MenuCommand(@NotNull ProtectionPlugin plugin) {
20+
super(plugin, new String[]{"menu", "gui"}, Perms.COMMAND_MENU);
21+
this.setUsage(plugin.getMessage(Lang.COMMAND_MENU_USAGE));
22+
this.setDescription(plugin.getMessage(Lang.COMMAND_MENU_DESC));
23+
this.setPlayerOnly(true);
24+
}
25+
26+
@Override
27+
public @NotNull List<String> getTab(@NotNull Player player, int arg, @NotNull String[] args) {
28+
RegionUser user = plugin.getUserManager().getUserData(player);
29+
if (arg == 1) {
30+
return new ArrayList<>(user.getRegions().keySet());
31+
}
32+
return super.getTab(player, arg, args);
33+
}
34+
35+
@Override
36+
protected void onExecute(@NotNull CommandSender sender, @NotNull CommandResult result) {
37+
if (!(sender instanceof Player player)) {
38+
this.errorSender(sender);
39+
return;
40+
}
41+
if (result.length() == 0) {
42+
this.printUsage(sender);
43+
return;
44+
}
45+
46+
Region region = this.plugin.getRegionManager().getRegionById(result.getArg(1));
47+
if (region == null) {
48+
this.plugin.getMessage(Lang.ERROR_REGION_NOT_FOUND).send(sender);
49+
return;
50+
}
51+
52+
if (!region.isAllowed(player)) {
53+
return;
54+
}
55+
region.getRegionMenu().open(player, 1);
56+
plugin.getMessage(Lang.COMMAND_MENU_DONE)
57+
.replace(Placeholders.forLocation(region.getBlockLocation()))
58+
.replace(Placeholders.forPlayer(player))
59+
.send(sender);
60+
}
61+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package t.me.p1azmer.plugin.protectionblocks.commands;
2+
3+
import org.bukkit.command.CommandSender;
4+
import org.bukkit.entity.Player;
5+
import org.jetbrains.annotations.NotNull;
6+
import t.me.p1azmer.engine.api.command.AbstractCommand;
7+
import t.me.p1azmer.engine.api.command.CommandResult;
8+
import t.me.p1azmer.plugin.protectionblocks.Perms;
9+
import t.me.p1azmer.plugin.protectionblocks.Placeholders;
10+
import t.me.p1azmer.plugin.protectionblocks.ProtectionPlugin;
11+
import t.me.p1azmer.plugin.protectionblocks.config.Lang;
12+
import t.me.p1azmer.plugin.protectionblocks.data.impl.RegionUser;
13+
import t.me.p1azmer.plugin.protectionblocks.region.impl.Region;
14+
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
18+
public class TeleportCommand extends AbstractCommand<ProtectionPlugin> {
19+
public TeleportCommand(@NotNull ProtectionPlugin plugin) {
20+
super(plugin, new String[]{"teleport", "tp"}, Perms.COMMAND_TELEPORT);
21+
this.setUsage(plugin.getMessage(Lang.COMMAND_TELEPORT_USAGE));
22+
this.setDescription(plugin.getMessage(Lang.COMMAND_TELEPORT_DESC));
23+
this.setPlayerOnly(true);
24+
}
25+
26+
@Override
27+
public @NotNull List<String> getTab(@NotNull Player player, int arg, @NotNull String[] args) {
28+
RegionUser user = plugin.getUserManager().getUserData(player);
29+
if (arg == 1) {
30+
return new ArrayList<>(user.getRegions().keySet());
31+
}
32+
return super.getTab(player, arg, args);
33+
}
34+
35+
@Override
36+
protected void onExecute(@NotNull CommandSender sender, @NotNull CommandResult result) {
37+
if (!(sender instanceof Player player)) {
38+
this.errorSender(sender);
39+
return;
40+
}
41+
if (result.length() == 0) {
42+
this.printUsage(sender);
43+
return;
44+
}
45+
46+
Region region = this.plugin.getRegionManager().getRegionById(result.getArg(1));
47+
if (region == null) {
48+
this.plugin.getMessage(Lang.ERROR_REGION_NOT_FOUND).send(sender);
49+
return;
50+
}
51+
52+
if (!region.isAllowed(player)) {
53+
return;
54+
}
55+
player.teleport(region.getBlockLocation().clone().add(0.5, 1, 0.5));
56+
plugin.getMessage(Lang.COMMAND_TELEPORT_DONE)
57+
.replace(Placeholders.forLocation(region.getBlockLocation()))
58+
.replace(Placeholders.forPlayer(player))
59+
.send(sender);
60+
}
61+
}

src/main/java/t/me/p1azmer/plugin/protectionblocks/config/Lang.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@ public class Lang extends EngineLang {
1111

1212
public static final LangKey COMMAND_GIVE_DESC = LangKey.of("Command.Give.Desc", "Give specified region block to a player.");
1313
public static final LangKey COMMAND_GIVE_USAGE = LangKey.of("Command.Give.Usage", "<region block> <player> <amount>");
14-
public static final LangKey COMMAND_GIVE_DONE = LangKey.of("Command.Give.Done", "Given &ax%amount% %region_block_name%&7 to &a%player_name%&7.");
14+
public static final LangKey COMMAND_GIVE_DONE = LangKey.of("Command.Give.Done", GRAY + "Given " + GREEN + "x%amount% %region_block_name%" + GRAY + " to " + GREEN + "%player_name%" + GRAY + ".");
15+
16+
public static final LangKey COMMAND_TELEPORT_DESC = LangKey.of("Command.Teleport.Desc", "Teleport to the region block.");
17+
public static final LangKey COMMAND_TELEPORT_USAGE = LangKey.of("Command.Teleport.Usage", "<region_id>");
18+
public static final LangKey COMMAND_TELEPORT_DONE = LangKey.of("Command.Teleport.Done", GREEN + "You have successfully teleported to the region block!");
19+
20+
public static final LangKey COMMAND_MENU_DESC = LangKey.of("Command.Menu.Desc", "Open the Menu of region block.");
21+
public static final LangKey COMMAND_MENU_USAGE = LangKey.of("Command.Menu.Usage", "<region_id>");
22+
public static final LangKey COMMAND_MENU_DONE = LangKey.of("Command.Menu.Done", GREEN + "The region block menu is open!");
1523

1624
public static final LangKey ERROR_REGION_BLOCK_INVALID = LangKey.of("Error.Region_Block.Invalid", RED + "Invalid Region Block!");
1725

26+
public static final LangKey ERROR_REGION_NOT_FOUND = LangKey.of("Error.Region.Not_Found", RED + "Region not found!");
1827
public static final LangKey REGION_SUCCESS_CREATED = LangKey.of("Messages.Region.Success.Created", GREEN + "New Region successfully created!");
1928
public static final LangKey REGION_ERROR_CREATED_NEARBY_RG = LangKey.of("Messages.Region.Error.Nearby_Region", RED + "You cannot create a region here, as it will cross over with another one!");
2029
public static final LangKey REGION_ERROR_CREATED_LIMIT = LangKey.of("Messages.Region.Error.Limit", RED + "You cannot create a region of this type because you have reached the limit!");

src/main/java/t/me/p1azmer/plugin/protectionblocks/data/DataHandler.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ protected DataHandler(@NotNull ProtectionPlugin plugin) {
3333
long lastOnline = resultSet.getLong(COLUMN_USER_LAST_ONLINE.getName());
3434

3535
Map<String, String> regions = gson.fromJson(resultSet.getString(COLUMN_REGIONS.getName()), new TypeToken<Map<String, String>>() {}.getType());
36+
this.mapSwapper(regions);
3637

3738
return new RegionUser(plugin, uuid, name, dateCreated, lastOnline, regions);
3839
}
@@ -43,6 +44,24 @@ protected DataHandler(@NotNull ProtectionPlugin plugin) {
4344
};
4445
}
4546

47+
private void mapSwapper(@NotNull Map<String, String> map) { // bad but easy method
48+
Map<String, String> updatedMap = new HashMap<>();
49+
50+
for (Map.Entry<String, String> entry : map.entrySet()) {
51+
String key = entry.getKey();
52+
String value = entry.getValue();
53+
54+
if (plugin.getRegionManager().getRegionBlockById(key) != null) {
55+
updatedMap.put(value, key);
56+
} else {
57+
updatedMap.put(key, value);
58+
}
59+
}
60+
61+
map.clear();
62+
map.putAll(updatedMap);
63+
}
64+
4665
@NotNull
4766
public static synchronized DataHandler getInstance(@NotNull ProtectionPlugin plugin) {
4867
if (instance == null) {

src/main/java/t/me/p1azmer/plugin/protectionblocks/data/impl/RegionUser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ public void addRegion(@NotNull Region region, @NotNull RegionBlock regionBlock)
4646
}
4747

4848
public void addRegion(@NotNull String regionId, @NotNull String regionBlockId) {
49-
this.regions.put(regionBlockId.toLowerCase(), regionId.toLowerCase());
49+
this.regions.put(regionId.toLowerCase(), regionBlockId.toLowerCase());
5050
}
5151

5252
public void removeRegion(@NotNull Region region) {
53-
this.regions.remove(region.getId());
53+
this.regions.remove(region.getId(), region.getRegionBlockId());
5454
}
5555

5656
public long getAmountOf(@NotNull RegionBlock regionBlock) {
57-
return this.regions.values().stream().filter(founder -> regionBlock.getId().equals(founder)).count();
57+
return this.regions.values().stream().filter(founder -> regionBlock.getId().equals(founder.toLowerCase())).count();
5858
}
5959
}

src/main/java/t/me/p1azmer/plugin/protectionblocks/region/RegionManager.java

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ public Region getRegionByBlock(@NotNull Block block) {
142142
return this.getRegionByLocation(block.getLocation());
143143
}
144144

145+
@Nullable
146+
public Region getRegionById(@NotNull String id){
147+
return this.getRegions().stream().filter(region-> region.getId().equalsIgnoreCase(id)).findFirst().orElse(null);
148+
}
149+
145150
public boolean isProtectedBlock(@NotNull Block block) {
146151
return this.getRegionByBlock(block) != null;
147152
}
@@ -169,64 +174,63 @@ public boolean create(@NotNull String id) {
169174
return true;
170175
}
171176

172-
public void tryCreateRegion(@NotNull Player player, @NotNull Block block, @NotNull ItemStack item, @NotNull RegionBlock regionBlock) {
177+
public boolean tryCreateRegion(@NotNull Player player, @NotNull Block block, @NotNull ItemStack item, @NotNull RegionBlock regionBlock) {
173178
Region region = this.getRegionByBlock(block);
174-
if (region != null && !region.isAllowed(player)) return;
175-
if (!regionBlock.getWorlds().contains(block.getWorld().getName())) return;
179+
if (region != null && !region.isAllowed(player) || !regionBlock.getWorlds().contains(block.getWorld().getName()))
180+
return false;
176181

177182
if (regionBlock.isPlaceLimitEnabled() && regionBlock.getPlaceLimit() != null) {
178183
RegionUser regionUser = plugin.getUserManager().getUserData(player);
179184
int limit = regionBlock.getPlaceLimit().getBestValue(player, 0);
180185
if (regionUser.getAmountOf(regionBlock) >= limit) {
181186
plugin.getMessage(Lang.REGION_ERROR_CREATED_LIMIT).send(player);
182-
return;
187+
return false;
183188
}
184189
}
185190

186191
this.createRegion(player, block, regionBlock);
192+
return true;
187193
}
188194

189195
public void createRegion(@NotNull Player player, @NotNull Block block, @NotNull RegionBlock regionBlock) {
190196
JYML cfg = new JYML(this.plugin.getDataFolder() + Config.REGION_DIR, UUID.randomUUID().toString().substring(0, 7).replace("-", "") + "-" + (this.getRegions().size() + 1) + ".yml");
191197
Region region = new Region(this, cfg);
192198

193-
plugin.runTask(sync -> {
194-
region.setRegionBlockId(regionBlock.getId());
195-
region.setOwner(player.getUniqueId());
196-
region.setOwnerName(player.getName());
197-
if (regionBlock.getLifeTime() != null && regionBlock.isLifeTimeEnabled())
198-
region.setLastDeposit(System.currentTimeMillis() + regionBlock.getLifeTime().getBestValue(player, 1000) * 1000L);
199-
else
200-
region.setLastDeposit(-1);
201-
region.setBlockLocation(block.getLocation(), regionBlock, player);
202-
region.setBlockHealth(regionBlock.getStrength());
203-
region.save();
204-
205-
this.getRegionMap().put(region.getId(), region);
206-
207-
block.setMetadata(Keys.REGION_BLOCK.getKey(), new FixedMetadataValue(plugin, region.getId()));
208-
// small & pretty effect
209-
Location loc = block.getLocation().clone().add(0.5, -0.8D, 0.5);
210-
for (int step = 0; step < 170 / 5; ++step) {
211-
for (int boost = 0; boost < 3; boost++) {
212-
for (int strand = 1; strand <= 2; ++strand) {
213-
float progress = step / (float) (170 / 5);
214-
double point = 2.0F * progress * 2.0f * Math.PI / 2 + 6.283185307179586 * strand / 2 + 0.7853981633974483D;
215-
double addX = Math.cos(point) * progress * 1.5F;
216-
double addZ = Math.sin(point) * progress * 1.5F;
217-
double addY = 3.5D - 0.02 * 5 * step;
218-
Location location = loc.clone().add(addX, addY, addZ);
219-
UniParticle.redstone(Color.LIME, 1).play(location, 0.1f, 0.0f, 1);
220-
}
199+
region.setRegionBlockId(regionBlock.getId());
200+
region.setOwner(player.getUniqueId());
201+
region.setOwnerName(player.getName());
202+
if (regionBlock.getLifeTime() != null && regionBlock.isLifeTimeEnabled())
203+
region.setLastDeposit(System.currentTimeMillis() + regionBlock.getLifeTime().getBestValue(player, 1000) * 1000L);
204+
else
205+
region.setLastDeposit(-1);
206+
region.setBlockLocation(block.getLocation(), regionBlock, player);
207+
region.setBlockHealth(regionBlock.getStrength());
208+
region.save();
209+
210+
this.getRegionMap().put(region.getId(), region);
211+
212+
block.setMetadata(Keys.REGION_BLOCK.getKey(), new FixedMetadataValue(plugin, region.getId()));
213+
// small & pretty effect
214+
Location loc = block.getLocation().clone().add(0.5, -0.8D, 0.5);
215+
for (int step = 0; step < 170 / 5; ++step) {
216+
for (int boost = 0; boost < 3; boost++) {
217+
for (int strand = 1; strand <= 2; ++strand) {
218+
float progress = step / (float) (170 / 5);
219+
double point = 2.0F * progress * 2.0f * Math.PI / 2 + 6.283185307179586 * strand / 2 + 0.7853981633974483D;
220+
double addX = Math.cos(point) * progress * 1.5F;
221+
double addZ = Math.sin(point) * progress * 1.5F;
222+
double addY = 3.5D - 0.02 * 5 * step;
223+
Location location = loc.clone().add(addX, addY, addZ);
224+
UniParticle.redstone(Color.LIME, 1).play(location, 0.1f, 0.0f, 1);
221225
}
222226
}
223-
regionBlock.updateHologram(region);
227+
}
228+
regionBlock.updateHologram(region);
224229

225-
plugin.getMessage(Lang.REGION_SUCCESS_CREATED)
226-
.replace(regionBlock.replacePlaceholders())
227-
.replace(region.replacePlaceholders())
228-
.send(player);
229-
});
230+
plugin.getMessage(Lang.REGION_SUCCESS_CREATED)
231+
.replace(regionBlock.replacePlaceholders())
232+
.replace(region.replacePlaceholders())
233+
.send(player);
230234

231235
plugin.getUserManager().getUserDataAndPerform(player.getUniqueId(), regionUser -> {
232236
regionUser.addRegion(region, regionBlock);

src/main/java/t/me/p1azmer/plugin/protectionblocks/region/impl/RegionBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public void setPlaceLimitEnabled(boolean placeLimitEnabled) {
304304
this.placeLimitEnabled = placeLimitEnabled;
305305
if (placeLimitEnabled) {
306306
if (!this.getConfig().contains("Limits.Place.Groups")) {
307-
new PlayerRankMap<>(Map.of(DEFAULT, 3))
307+
new PlayerRankMap<>(Map.of(DEFAULT, 3, "admin", -1))
308308
.write(this.getConfig(), "Limits.Place.Groups");
309309
}
310310
this.placeLimit = PlayerRankMap.readInt(cfg, "Limits.Place.Groups");

0 commit comments

Comments
 (0)