Skip to content
Permalink
Browse files

Enlarging a region

  • Loading branch information...
MarcinWieczorek committed May 13, 2017
1 parent 75bb9c0 commit 3d292cc7b2ef234f9188febfbbfca708b29d70b6
@@ -407,6 +407,10 @@ mvn clean install
<td>novaguilds.admin.region.buy</td>
<td>/nga rg <guild> buy</td>
</tr>
<tr>
<td>novaguilds.admin.region.enlarge</td>
<td>/nga rg <guild> enlarge [index]</td>
</tr>
<tr>
<td>novaguilds.admin.region.teleport.other</td>
<td>/nga rg tp <guild></td>
@@ -599,6 +603,10 @@ mvn clean install
<td>novaguilds.region.delete</td>
<td>/g rg delete</td>
</tr>
<tr>
<td>novaguilds.region.enlarge</td>
<td>/g rg enlarge [index]</td>
</tr>
<tr>
<td>novaguilds.region.list</td>
<td>/g rg list</td>
@@ -34,6 +34,7 @@
HIGHLIGHT_RESIZE,
CREATE,
RESIZE,
ENLARGE,
NONE
}

@@ -19,6 +19,7 @@
package co.marcin.novaguilds.command;

import co.marcin.novaguilds.api.basic.NovaGroup;
import co.marcin.novaguilds.api.util.reflect.FieldAccessor;
import co.marcin.novaguilds.command.abstractexecutor.AbstractCommandExecutor;
import co.marcin.novaguilds.enums.Command;
import co.marcin.novaguilds.enums.Config;
@@ -29,6 +30,7 @@
import co.marcin.novaguilds.util.TabUtils;
import co.marcin.novaguilds.util.TagUtils;
import co.marcin.novaguilds.util.VersionUtils;
import co.marcin.novaguilds.util.reflect.Reflections;
import org.bukkit.command.CommandSender;

import java.util.HashMap;
@@ -96,24 +98,11 @@ public void execute(CommandSender sender, String[] args) throws Exception {
}

sender.sendMessage("name = " + group.getName());
sender.sendMessage("guildCreateMoney = " + group.get(NovaGroupImpl.Key.CREATE_MONEY));
sender.sendMessage("guildHomeMoney = " + group.get(NovaGroupImpl.Key.HOME_MONEY));
sender.sendMessage("guildJoinMoney = " + group.get(NovaGroupImpl.Key.JOIN_MONEY));
sender.sendMessage("guildCreateItems = " + group.get(NovaGroupImpl.Key.CREATE_ITEMS).toString());
sender.sendMessage("guildCreateSchematic = " + (group.get(NovaGroupImpl.Key.CREATE_SCHEMATIC) == null ? "no schematic" : group.get(NovaGroupImpl.Key.CREATE_SCHEMATIC).getName()));
sender.sendMessage("guildHomeItems = " + group.get(NovaGroupImpl.Key.HOME_ITEMS).toString());
sender.sendMessage("guildJoinItems = " + group.get(NovaGroupImpl.Key.JOIN_ITEMS).toString());
sender.sendMessage("guildBuyLifeItems = " + group.get(NovaGroupImpl.Key.BUY_LIFE_ITEMS).toString());
sender.sendMessage("guildBuySlotItems = " + group.get(NovaGroupImpl.Key.BUY_SLOT_ITEMS).toString());
sender.sendMessage("guildBuyBannerItems = " + group.get(NovaGroupImpl.Key.BUY_BANNER_ITEMS).toString());
sender.sendMessage("guildBuyLifeMoney = " + group.get(NovaGroupImpl.Key.BUY_LIFE_MONEY));
sender.sendMessage("guildBuySlotMoney = " + group.get(NovaGroupImpl.Key.BUY_SLOT_MONEY));
sender.sendMessage("guildBuyBannerMoney = " + group.get(NovaGroupImpl.Key.BUY_BANNER_MONEY));
sender.sendMessage("guildEffectMoney = " + group.get(NovaGroupImpl.Key.EFFECT_MONEY));
sender.sendMessage("guildTeleportDelay = " + group.get(NovaGroupImpl.Key.HOME_DELAY) + "s");
sender.sendMessage("regionCreateMoney = " + group.get(NovaGroupImpl.Key.REGION_CREATE_MONEY));
sender.sendMessage("regionPricePerBlock = " + group.get(NovaGroupImpl.Key.REGION_PRICEPERBLOCK));
sender.sendMessage("regionAutoSize = " + group.get(NovaGroupImpl.Key.REGION_AUTOSIZE));
for(FieldAccessor<NovaGroup.Key> field : Reflections.getFields(NovaGroupImpl.Key.class, NovaGroup.Key.class)) {
NovaGroup.Key key = field.get();

sender.sendMessage(field.getName() + " = " + group.get(key));
}
break;
case "g":
case "guild":
@@ -34,6 +34,7 @@ public CommandRegion() {
commandsMap.put("create", Command.REGION_BUY);
commandsMap.put("delete", Command.REGION_DELETE);
commandsMap.put("del", Command.REGION_DELETE);
commandsMap.put("enlarge",Command.REGION_ENLARGE);
}

@Override
@@ -37,12 +37,18 @@
import co.marcin.novaguilds.manager.GroupManager;
import co.marcin.novaguilds.manager.ListenerManager;
import co.marcin.novaguilds.manager.PlayerManager;
import co.marcin.novaguilds.util.InventoryUtils;
import co.marcin.novaguilds.util.RegionUtils;
import co.marcin.novaguilds.util.StringUtils;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class CommandRegionBuy extends AbstractCommandExecutor {
@@ -56,14 +62,17 @@ public void execute(CommandSender sender, String[] args) throws Exception {
}

NovaGuild guild = nPlayer.getGuild();
RegionSelection activeSelection = nPlayer.getActiveSelection();

if(!nPlayer.hasPermission(nPlayer.getPreferences().getRegionMode() == RegionMode.RESIZE ? GuildPermission.REGION_RESIZE : GuildPermission.REGION_CREATE)) {
if(!nPlayer.hasPermission(nPlayer.getPreferences().getRegionMode() == RegionMode.RESIZE
|| activeSelection.getType() == RegionSelection.Type.RESIZE
|| activeSelection.getType() == RegionSelection.Type.ENLARGE
? GuildPermission.REGION_RESIZE
: GuildPermission.REGION_CREATE)) {
Message.CHAT_GUILD_NOGUILDPERM.send(sender);
return;
}

RegionSelection activeSelection = nPlayer.getActiveSelection();

if(activeSelection == null || !activeSelection.hasBothSelections()) {
Message.CHAT_REGION_VALIDATION_NOTSELECTED.send(sender);
return;
@@ -81,19 +90,25 @@ public void execute(CommandSender sender, String[] args) throws Exception {

int regionSize = RegionUtils.checkRegionSize(selectedLocation0, selectedLocation1);

if(guild.getRegions().size() >= Config.REGION_MAXAMOUNT.getInt() && nPlayer.getPreferences().getRegionMode() != RegionMode.RESIZE) {
if(guild.getRegions().size() >= Config.REGION_MAXAMOUNT.getInt()
&& nPlayer.getPreferences().getRegionMode() != RegionMode.RESIZE) {
Message.CHAT_REGION_MAXAMOUNT.clone().setVar(VarKey.AMOUNT, Config.REGION_MAXAMOUNT.getInt()).send(nPlayer);
return;
}

//region's price
double price;
List<ItemStack> itemStackList = new ArrayList<>();
NovaGroup group = GroupManager.getGroup(sender);
double ppb = group.get(NovaGroupImpl.Key.REGION_PRICEPERBLOCK);

if(nPlayer.getPreferences().getRegionMode() == RegionMode.RESIZE) {
if(activeSelection.getType() == RegionSelection.Type.RESIZE) {
price = ppb * (regionSize - activeSelection.getSelectedRegion().getSurface());
}
else if(activeSelection.getType() == RegionSelection.Type.ENLARGE) {
price = group.get(NovaGroupImpl.Key.REGION_ENLARGE_MONEY);
itemStackList = group.get(NovaGroupImpl.Key.REGION_ENLARGE_ITEMS);
}
else {
price = ppb * regionSize + group.get(NovaGroupImpl.Key.REGION_CREATE_MONEY);
}
@@ -103,10 +118,22 @@ public void execute(CommandSender sender, String[] args) throws Exception {
return;
}

if(!itemStackList.isEmpty()) {
List<ItemStack> missingItems = InventoryUtils.getMissingItems(((Player) sender).getInventory(), itemStackList);

if(!missingItems.isEmpty()) {
Message.CHAT_CREATEGUILD_NOITEMS.send(sender);
sender.sendMessage(StringUtils.getItemList(missingItems));
return;
}
}

Cancellable event;
NovaRegion region;

if(nPlayer.getPreferences().getRegionMode() == RegionMode.RESIZE) {
if(activeSelection.getType() == RegionSelection.Type.RESIZE
|| activeSelection.getType() == RegionSelection.Type.RESIZE
|| activeSelection.getType() == RegionSelection.Type.ENLARGE) {
region = activeSelection.getSelectedRegion();

event = new RegionResizeEvent(region, nPlayer, activeSelection, false);
@@ -136,6 +163,10 @@ public void execute(CommandSender sender, String[] args) throws Exception {
guild.takeMoney(price);
}

if(!itemStackList.isEmpty()) {
InventoryUtils.removeItems((Player) sender, itemStackList);
}

nPlayer.cancelToolProgress();
plugin.getRegionManager().checkAtRegionChange();
}
@@ -0,0 +1,92 @@
/*
* NovaGuilds - Bukkit plugin
* Copyright (C) 2017 Marcin (CTRL) Wieczorek
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/

package co.marcin.novaguilds.command.region;

import co.marcin.novaguilds.api.basic.NovaPlayer;
import co.marcin.novaguilds.api.basic.NovaRegion;
import co.marcin.novaguilds.api.util.RegionSelection;
import co.marcin.novaguilds.command.abstractexecutor.AbstractCommandExecutor;
import co.marcin.novaguilds.enums.Command;
import co.marcin.novaguilds.enums.Message;
import co.marcin.novaguilds.impl.basic.NovaGroupImpl;
import co.marcin.novaguilds.impl.util.RegionSelectionImpl;
import co.marcin.novaguilds.manager.GroupManager;
import co.marcin.novaguilds.manager.PlayerManager;
import co.marcin.novaguilds.util.NumberUtils;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;

public class CommandRegionEnlarge extends AbstractCommandExecutor {
@Override
public void execute(CommandSender sender, String[] args) throws Exception {
NovaPlayer nPlayer = PlayerManager.getPlayer(sender);

if(nPlayer.getActiveSelection() != null) {
nPlayer.getActiveSelection().reset();
}

NovaRegion region;
if(args.length == 0) {
region = nPlayer.getAtRegion();
}
else {
String indexString = args[0];

if(!NumberUtils.isNumeric(indexString)) {
Message.CHAT_ENTERINTEGER.send(sender);
return;
}

int index = Integer.parseInt(indexString);

region = nPlayer.getGuild().getRegion(index);
}

RegionSelection selection = new RegionSelectionImpl(nPlayer, RegionSelection.Type.ENLARGE, region);
Location corner0 = selection.getCorner(0);
Location corner1 = selection.getCorner(1);
int diff = GroupManager.getGroup(sender).get(NovaGroupImpl.Key.REGION_ENLARGE_BLOCKS);

if(corner0.getBlockX() < corner1.getBlockX()
&& corner0.getBlockZ() < corner1.getBlockZ()) {
corner0.add(-diff, 0, -diff);
corner1.subtract(-diff, 0, -diff);
}

if(corner0.getBlockX() < corner1.getBlockX()
&& corner0.getBlockZ() > corner1.getBlockZ()) {
corner0.add(-diff, 0, diff);
corner1.subtract(-diff, 0, diff);
}

if(corner0.getBlockX() > corner1.getBlockX()
&& corner0.getBlockZ() > corner1.getBlockZ()) {
corner0.add(diff, 0, diff);
corner1.subtract(diff, 0, diff);
}

if(corner0.getBlockX() > corner1.getBlockX()
&& corner0.getBlockZ() < corner1.getBlockZ()) {
corner0.add(diff, 0, -diff);
corner1.subtract(diff, 0, -diff);
}

Command.REGION_BUY.execute(sender, new String[0]);
}
}
@@ -107,6 +107,7 @@
import co.marcin.novaguilds.command.region.CommandRegion;
import co.marcin.novaguilds.command.region.CommandRegionBuy;
import co.marcin.novaguilds.command.region.CommandRegionDelete;
import co.marcin.novaguilds.command.region.CommandRegionEnlarge;
import co.marcin.novaguilds.impl.basic.CommandWrapperImpl;
import co.marcin.novaguilds.util.LoggerUtils;
import org.bukkit.command.TabCompleter;
@@ -200,6 +201,7 @@
public static final CommandWrapper REGION_ACCESS = new Command(CommandRegion.class, Permission.NOVAGUILDS_REGION_ACCESS, Message.CHAT_USAGE_REGION_ACCESS, Flag.NOCONSOLE );
public static final CommandWrapper REGION_BUY = new Command(CommandRegionBuy.class, Permission.NOVAGUILDS_REGION_CREATE, Message.CHAT_USAGE_REGION_BUY, Flag.NOCONSOLE );
public static final CommandWrapper REGION_DELETE = new Command(CommandRegionDelete.class, Permission.NOVAGUILDS_REGION_DELETE, Message.CHAT_USAGE_REGION_DELETE, Flag.NOCONSOLE, Flag.CONFIRM);
public static final CommandWrapper REGION_ENLARGE = new Command(CommandRegionEnlarge.class, Permission.NOVAGUILDS_REGION_ENLARGE, Message.CHAT_USAGE_REGION_ENLARGE, Flag.NOCONSOLE );
public static final CommandWrapper TOOL_GET = new Command(CommandToolGet.class, Permission.NOVAGUILDS_TOOL_GET, Message.CHAT_USAGE_TOOL, Flag.NOCONSOLE );
public static final CommandWrapper PLAYERINFO = new Command(CommandPlayerInfo.class, Permission.NOVAGUILDS_PLAYERINFO, "playerinfo", Message.CHAT_USAGE_PLAYER_INFO );
public static final CommandWrapper NOVAGUILDS = new Command(CommandNovaGuilds.class, Permission.NOVAGUILDS_NOVAGUILDS, "novaguilds" );
@@ -61,6 +61,7 @@
REGION_CREATE,
REGION_REMOVE,
REGION_RESIZE,
REGION_ENLARGE,

RANK_DELETE,
RANK_LIST,
@@ -354,6 +354,7 @@
public static MessageWrapper CHAT_USAGE_NGA_REGION_ACCESS = new MessageWrapperImpl(MessageWrapper.Flag.NOPREFIX);
public static MessageWrapper CHAT_USAGE_NGA_REGION_BYPASS;
public static MessageWrapper CHAT_USAGE_NGA_REGION_DELETE;
public static MessageWrapper CHAT_USAGE_NGA_REGION_ENLARGE;
public static MessageWrapper CHAT_USAGE_NGA_REGION_LIST;
public static MessageWrapper CHAT_USAGE_NGA_REGION_SPECTATE;
public static MessageWrapper CHAT_USAGE_NGA_REGION_TELEPORT;
@@ -395,6 +396,7 @@
public static MessageWrapper CHAT_USAGE_REGION_ACCESS;
public static MessageWrapper CHAT_USAGE_REGION_BUY;
public static MessageWrapper CHAT_USAGE_REGION_DELETE;
public static MessageWrapper CHAT_USAGE_REGION_ENLARGE;
public static MessageWrapper CHAT_USAGE_REGION_LIST;

public static MessageWrapper CHAT_USAGE_TOOL;
@@ -514,6 +516,7 @@
public static MessageWrapper INVENTORY_GUI_PERMISSIONS_TITLE;
public static MessageWrapper INVENTORY_GUI_PERMISSIONS_ITEM_ENABLED;
public static MessageWrapper INVENTORY_GUI_PERMISSIONS_ITEM_DISABLED;
public static MessageWrapper INVENTORY_GUI_REGION_ENLARGE;

public static MessageWrapper INVENTORY_GUI_PERMISSIONS_NAMES_BLOCK_BREAK;
public static MessageWrapper INVENTORY_GUI_PERMISSIONS_NAMES_BLOCK_PLACE;
@@ -551,6 +554,7 @@
public static MessageWrapper INVENTORY_GUI_PERMISSIONS_NAMES_REGION_CREATE;
public static MessageWrapper INVENTORY_GUI_PERMISSIONS_NAMES_REGION_REMOVE;
public static MessageWrapper INVENTORY_GUI_PERMISSIONS_NAMES_REGION_RESIZE;
public static MessageWrapper INVENTORY_GUI_PERMISSIONS_NAMES_REGION_ENLARGE;
public static MessageWrapper INVENTORY_GUI_PERMISSIONS_NAMES_RANK_LIST;
public static MessageWrapper INVENTORY_GUI_PERMISSIONS_NAMES_RANK_SET;
public static MessageWrapper INVENTORY_GUI_PERMISSIONS_NAMES_RANK_EDIT;
@@ -78,6 +78,7 @@
NOVAGUILDS_ADMIN_REGION_LIST,
NOVAGUILDS_ADMIN_REGION_TELEPORT_SELF,
NOVAGUILDS_ADMIN_REGION_BUY,
NOVAGUILDS_ADMIN_REGION_ENLARGE,
NOVAGUILDS_ADMIN_REGION_TELEPORT_OTHER,
NOVAGUILDS_ADMIN_REGION_SPECTATE,
NOVAGUILDS_ADMIN_RELOAD,
@@ -128,6 +129,7 @@
NOVAGUILDS_REGION_CREATE,
NOVAGUILDS_REGION_RESIZE,
NOVAGUILDS_REGION_DELETE,
NOVAGUILDS_REGION_ENLARGE,
NOVAGUILDS_REGION_LIST,

NOVAGUILDS_CHAT_NOTAG,
@@ -57,6 +57,9 @@
public static final NovaGroup.Key<Double> REGION_CREATE_MONEY = new NovaGroupImpl.Key<>(Double.class);
public static final NovaGroup.Key<Double> REGION_PRICEPERBLOCK = new NovaGroupImpl.Key<>(Double.class);
public static final NovaGroup.Key<Integer> REGION_AUTOSIZE = new NovaGroupImpl.Key<>(Integer.class);
public static final NovaGroup.Key<Integer> REGION_ENLARGE_BLOCKS = new NovaGroupImpl.Key<>(Integer.class);
public static final NovaGroup.Key<Double> REGION_ENLARGE_MONEY = new NovaGroupImpl.Key<>(Double.class);
public static final NovaGroup.Key<List<ItemStack>> REGION_ENLARGE_ITEMS = new NovaGroupImpl.Key<>();

private final Class<T> type;

@@ -125,6 +128,9 @@ public Key(Class<T> type) {
put(Key.REGION_CREATE_MONEY, "region.createmoney");
put(Key.REGION_PRICEPERBLOCK, "region.ppb");
put(Key.REGION_AUTOSIZE, "region.autoregionsize");
put(Key.REGION_ENLARGE_BLOCKS, "region.enlarge.blocks");
put(Key.REGION_ENLARGE_MONEY, "region.enlarge.money");
put(Key.REGION_ENLARGE_ITEMS, "region.enlarge.items");
}};

private final String name;
@@ -202,7 +202,15 @@ public void setInvitedTo(Collection<NovaGuild> list) {

@Override
public void setActiveSelection(RegionSelection selection) {
if(activeSelection != null) {
activeSelection.removeSpectator(this);
}

activeSelection = selection;

if(activeSelection != null) {
activeSelection.addSpectator(this);
}
}

@Override
Oops, something went wrong.

0 comments on commit 3d292cc

Please sign in to comment.
You can’t perform that action at this time.