Skip to content

Commit c55417d

Browse files
committed
Add command to toggle pvp
1 parent d2bd773 commit c55417d

File tree

5 files changed

+61
-17
lines changed

5 files changed

+61
-17
lines changed

uSkyBlock-Core/src/main/java/us/talabrek/ultimateskyblock/challenge/Challenge.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
public class Challenge {
2626
public static final Pattern REQ_PATTERN = Pattern.compile("(?<itemstack>(?<type>[0-9A-Z_]+)(:(?<subtype>[0-9]+))?(?<meta>\\{.*\\})?):(?<amount>[0-9]+)(;(?<op>[+\\-*\\^])(?<inc>[0-9]+))?");
2727
public static final int MAX_DETAILS = 11;
28-
public static final int MAX_LINE = 30;
28+
public static final int MAX_LINE = 20;
2929

3030
public enum Type {
3131
PLAYER, ISLAND, ISLAND_LEVEL;
@@ -159,7 +159,10 @@ public ItemStack getDisplayItem(ChallengeCompletion completion, boolean withCurr
159159
ItemStack currentChallengeItem = getDisplayItem();
160160
ItemMeta meta = currentChallengeItem.getItemMeta();
161161
List<String> lores = new ArrayList<>();
162-
lores.addAll(prefix(wordWrap(getDescription(), MAX_LINE), "\u00a77"));
162+
for(String str : getDescription().split("\\\\n")) {
163+
lores.add("\u00a77"+str);
164+
}
165+
//lores.addAll(prefix(wordWrap(getDescription(), MAX_LINE), "\u00a77"));
163166
Reward reward = getReward();
164167
if (completion.getTimesCompleted() > 0 && isRepeatable()) {
165168
currentChallengeItem.setAmount(completion.getTimesCompleted() < currentChallengeItem.getMaxStackSize() ? completion.getTimesCompleted() : currentChallengeItem.getMaxStackSize());

uSkyBlock-Core/src/main/java/us/talabrek/ultimateskyblock/command/IslandCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public IslandCommand(uSkyBlock plugin, SkyBlockMenu menu) {
7777
add(new PermCommand(plugin));
7878
add(new GreetingCommand(plugin));
7979
add(new Farewellcommand(plugin));
80+
add(new TogglePvpCommand(plugin));
8081
}
8182

8283
@Override
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package us.talabrek.ultimateskyblock.command.island;
2+
3+
import com.sk89q.worldguard.protection.flags.Flags;
4+
import com.sk89q.worldguard.protection.flags.StateFlag;
5+
import com.sk89q.worldguard.protection.managers.RegionManager;
6+
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
7+
import dk.lockfuglsang.minecraft.command.AbstractCommand;
8+
import org.bukkit.World;
9+
import org.bukkit.command.CommandSender;
10+
import org.bukkit.entity.Player;
11+
import us.talabrek.ultimateskyblock.api.IslandInfo;
12+
import us.talabrek.ultimateskyblock.handler.WorldGuardHandler;
13+
import us.talabrek.ultimateskyblock.uSkyBlock;
14+
15+
import java.util.Map;
16+
17+
import static dk.lockfuglsang.minecraft.po.I18nUtil.marktr;
18+
import static dk.lockfuglsang.minecraft.po.I18nUtil.tr;
19+
20+
public class TogglePvpCommand extends AbstractCommand {
21+
private final uSkyBlock plugin;
22+
23+
public TogglePvpCommand(uSkyBlock plugin) {
24+
super("togglepvp", "usb.island.create", marktr("Toggle PVP (allow/deny) of your island"));
25+
this.plugin = plugin;
26+
}
27+
28+
@Override
29+
public boolean execute(CommandSender sender, String alias, Map<String, Object> data, String... args) {
30+
Player player = (Player)sender;
31+
IslandInfo islandInfo = uSkyBlock.getInstance().getIslandInfo(player);
32+
ProtectedRegion rg = WorldGuardHandler.getIslandRegion(islandInfo.getName()+"island");
33+
if(rg.getFlag(Flags.PVP)!=null&&rg.getFlag(Flags.PVP).toString()=="ALLOW"){
34+
rg.setFlag(Flags.PVP,null);
35+
player.sendMessage(tr("\u00a7bPVP is now denied on your island!"));
36+
}else{
37+
rg.setFlag(Flags.PVP,StateFlag.State.ALLOW);
38+
player.sendMessage(tr("\u00a7bPVP is now allowed on your island!"));
39+
player.sendMessage(tr("\u00a7bPlease be careful that in order to protect visitors, you can't attack them. But they can harm island members."));
40+
}
41+
return true;
42+
}
43+
}

uSkyBlock-Core/src/main/java/us/talabrek/ultimateskyblock/handler/WorldGuardHandler.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
import com.sk89q.worldguard.domains.DefaultDomain;
88
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
99
import com.sk89q.worldguard.protection.ApplicableRegionSet;
10+
import com.sk89q.worldguard.protection.flags.Flag;
1011
import com.sk89q.worldguard.protection.flags.Flags;
1112
import com.sk89q.worldguard.protection.flags.StateFlag;
1213
import com.sk89q.worldguard.protection.managers.RegionManager;
1314
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
1415
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
1516
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
1617
import dk.lockfuglsang.minecraft.po.I18nUtil;
18+
import org.bukkit.Bukkit;
1719
import org.bukkit.Location;
1820
import org.bukkit.World;
1921
import org.bukkit.command.CommandSender;
@@ -212,7 +214,11 @@ public static void islandUnlock(final CommandSender sender, final String islandN
212214
LogUtil.log(Level.SEVERE, "ERROR: Failed to unlock " + islandName + "'s Island (" + sender.getName() + ")", ex);
213215
}
214216
}
215-
217+
public static ProtectedRegion getIslandRegion(String regionName){
218+
RegionManager regionManager = getRegionManager(Bukkit.getWorld(Settings.general_worldName));
219+
ProtectedRegion rg = regionManager.getRegion(regionName);
220+
return rg;
221+
}
216222
public static BlockVector3 getProtectionVectorLeft(final Location island) {
217223
return BlockVector3.at(island.getX() + Settings.island_radius - 1, 255.0, island.getZ() + Settings.island_radius - 1);
218224
}
@@ -247,18 +253,6 @@ public static ProtectedRegion getIslandRegionAt(Location location) {
247253
}
248254
return null;
249255
}
250-
public static boolean isPVPAllowed(Location location){
251-
RegionManager regionManager = getRegionManager(location.getWorld());
252-
if (regionManager == null) {
253-
return false;
254-
}
255-
Iterable<ProtectedRegion> applicableRegions = regionManager.getApplicableRegions(toVector(location));
256-
for (ProtectedRegion region : applicableRegions) {
257-
String id = region.getId().toLowerCase();
258-
System.out.println("region: "+id);
259-
}
260-
return false;
261-
}
262256
private static BlockVector3 toVector(Location location) {
263257
return BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ());
264258
}

uSkyBlock-Core/src/main/java/us/talabrek/ultimateskyblock/menu/SkyBlockMenu.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,8 +778,8 @@ private Inventory createMainMenu(Player player) {
778778

779779
menuItem = new ItemStack(Material.IRON_SWORD, 1);
780780
meta4 = menuItem.getItemMeta();
781-
meta4.setDisplayName(tr("\u00a7a\u00a7lAllow pvp"));
782-
addLore(lores, "\u00a7f", tr("allow/deny pvp"));
781+
meta4.setDisplayName(tr("\u00a7a\u00a7lToggle PVP"));
782+
addLore(lores, "\u00a7f", tr("Click to toggle PVP deny/allow state on your island."));
783783
meta4.setLore(lores);
784784
menuItem.setItemMeta(meta4);
785785
menu.setItem(47,menuItem);
@@ -979,6 +979,9 @@ private void onClickMainMenu(InventoryClickEvent event, ItemStack currentItem, P
979979
} else if (currentItem.getType() == Material.LIGHT_GRAY_BED) {
980980
p.closeInventory();
981981
p.performCommand("sethome");
982+
} else if (currentItem.getType() == Material.IRON_SWORD) {
983+
p.closeInventory();
984+
p.performCommand("island togglepvp");
982985
} else if (currentItem.getType() == Material.PAINTING) {
983986
p.closeInventory();
984987
p.performCommand("island top");

0 commit comments

Comments
 (0)