Skip to content

Commit

Permalink
Settings Compatibility and Pom Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Tolmikarc committed Sep 8, 2020
1 parent a312748 commit 7f74543
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 6 deletions.
6 changes: 3 additions & 3 deletions TownyMenu/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>

<groupId>net.tolmikarc</groupId>
<artifactId>TownyMenu</artifactId>
<version>1.0.9</version>
<artifactId>TownyMenu-PRE</artifactId>
<version>1.1.1</version>


<properties>
Expand Down Expand Up @@ -61,7 +61,7 @@
<dependency>
<groupId>com.github.TownyAdvanced</groupId>
<artifactId>Towny</artifactId>
<version>0.96.2.0</version>
<version>0.96.2.16</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
101 changes: 99 additions & 2 deletions TownyMenu/src/main/java/net/tolmikarc/townymenu/town/TownMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.*;
import com.palmergames.bukkit.towny.tasks.CooldownTimerTask;
import lombok.SneakyThrows;
import net.tolmikarc.townymenu.plot.PlotMenu;
import net.tolmikarc.townymenu.settings.Settings;
import net.tolmikarc.townymenu.town.prompt.*;
Expand All @@ -28,6 +30,7 @@
import org.mineacademy.fo.remain.CompMaterial;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;


Expand All @@ -48,7 +51,7 @@ public class TownMenu extends Menu {

private final static ItemStack DUMMY_BUTTON = ItemCreator.of(CompMaterial.GRAY_STAINED_GLASS_PANE, "").build().make();

public TownMenu(Town town, Player player) {
public TownMenu(Town town, Player player) throws NotRegisteredException {

List<Resident> residentList = town.getResidents();

Expand All @@ -72,7 +75,70 @@ public TownMenu(Town town, Player player) {

townyPermButton = new ButtonMenu(new TownyPermMenu(town), CompMaterial.STONE_AXE, "&c&lPermission Menu", "", "Adjust town permissions", "for residents, nation", "allies and outsiders.");

economyButton = new ButtonMenu(new EconomyManagementMenu(town), CompMaterial.EMERALD_BLOCK, "&a&lEconomy Management Menu", "", "Manage your town's money");
if (TownySettings.isBankActionLimitedToBankPlots()) {
if (TownyAPI.getInstance().getTownBlock(player.getLocation()) != null)
if (!TownyAPI.getInstance().getTownBlock(player.getLocation()).getType().equals(TownBlockType.BANK))
economyButton = new Button() {
@Override
public void onClickedInMenu(Player player, Menu menu, ClickType clickType) {
Common.tell(player, "&cYou must be in a bank plot to use this menu.");
player.closeInventory();
}

@Override
public ItemStack getItem() {
return ItemCreator.of(CompMaterial.EMERALD_BLOCK, "&a&lEconomy Management Menu", "", "Manage your town's money").build().make();
}
};
else
economyButton = new ButtonMenu(new EconomyManagementMenu(town), CompMaterial.EMERALD_BLOCK, "&a&lEconomy Management Menu", "", "Manage your town's money");
else
economyButton = new Button() {
@Override
public void onClickedInMenu(Player player, Menu menu, ClickType clickType) {
Common.tell(player, "&cYou must be in a bank plot to use this menu.");
player.closeInventory();
}

@Override
public ItemStack getItem() {
return ItemCreator.of(CompMaterial.EMERALD_BLOCK, "&a&lEconomy Management Menu", "", "Manage your town's money").build().make();
}
};
} else if (TownySettings.isBankActionDisallowedOutsideTown()) {
if (TownyAPI.getInstance().getTownBlock(player.getLocation()) != null)
if (!TownyAPI.getInstance().getTownBlock(player.getLocation()).getTown().equals(town)) {
economyButton = new Button() {
@Override
public void onClickedInMenu(Player player, Menu menu, ClickType clickType) {
Common.tell(player, "&cYou must be in your town to use this menu.");
player.closeInventory();
}

@Override
public ItemStack getItem() {
return ItemCreator.of(CompMaterial.EMERALD_BLOCK, "&a&lEconomy Management Menu", "", "Manage your town's money").build().make();
}
};
} else
economyButton = new ButtonMenu(new EconomyManagementMenu(town), CompMaterial.EMERALD_BLOCK, "&a&lEconomy Management Menu", "", "Manage your town's money");
else {
economyButton = new Button() {
@Override
public void onClickedInMenu(Player player, Menu menu, ClickType clickType) {
Common.tell(player, "&cYou must be in your town to use this menu.");
player.closeInventory();
}

@Override
public ItemStack getItem() {
return ItemCreator.of(CompMaterial.EMERALD_BLOCK, "&a&lEconomy Management Menu", "", "Manage your town's money").build().make();
}
};
}

} else
economyButton = new ButtonMenu(new EconomyManagementMenu(town), CompMaterial.EMERALD_BLOCK, "&a&lEconomy Management Menu", "", "Manage your town's money");

generalSettingsButton = new ButtonMenu(new GeneralSettingsMenu(town), CompMaterial.ENDER_CHEST, "&2&lOther Settings Menu", "", "Change various", "extra town settings.");

Expand Down Expand Up @@ -176,9 +242,40 @@ public ItemStack getItem() {
}
};
pvpToggle = new Button() {
@SneakyThrows
@Override
public void onClickedInMenu(Player player, Menu menu, ClickType click) {
if (TownySettings.getOutsidersPreventPVPToggle()) {
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
for (Player onlinePlayer : onlinePlayers) {
Resident onlinePlayerAsRes = TownyAPI.getInstance().getDataSource().getResident(onlinePlayer.getName());
if (onlinePlayerAsRes.hasTown()) {
if (!onlinePlayerAsRes.getTown().equals(town))
if (TownyAPI.getInstance().getTownBlock(onlinePlayer.getLocation()) != null)
if (TownyAPI.getInstance().getTownBlock(onlinePlayer.getLocation()).getTown().equals(town)) {
Common.tell(player, "&cCannot toggle PVP while outsiders are in your town.");
player.closeInventory();
return;
}
} else {
if (TownyAPI.getInstance().getTownBlock(onlinePlayer.getLocation()) != null)
if (TownyAPI.getInstance().getTownBlock(onlinePlayer.getLocation()).getTown().equals(town)) {
Common.tell(player, "&cCannot toggle PVP while outsiders are in your town.");
player.closeInventory();
return;
}
}
}
}
if (TownySettings.getPVPCoolDownTime() > 0) {
if (CooldownTimerTask.hasCooldown(town.getName(), CooldownTimerTask.CooldownType.PVP)) {
Common.tell(player, "&cYou cannot toggle pvp until the cooldown is complete.");
player.closeInventory();
return;
}
}
town.setPVP(!town.isPVP());
CooldownTimerTask.addCooldownTimer(town.getName(), CooldownTimerTask.CooldownType.PVP);
TownyAPI.getInstance().getDataSource().saveTown(town);
restartMenu();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected String getPrompt(ConversationContext ctx) {
return null;


town.setTownBoard(input);
town.setBoard(input);
TownyAPI.getInstance().getDataSource().saveTown(town);

tell("&3Successfully set town board!");
Expand Down

0 comments on commit 7f74543

Please sign in to comment.