Skip to content

Commit

Permalink
player info flags
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperRonanCraft committed Jun 14, 2023
1 parent 919e458 commit 0203c28
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package me.SuperRonanCraft.BetterRTPAddons.addons.magicStick;

import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_TYPE;
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_CancelledEvent;
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_TeleportPostEvent;
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP;
import me.SuperRonanCraft.BetterRTP.references.messages.Message;
import me.SuperRonanCraft.BetterRTPAddons.Main;
import me.SuperRonanCraft.BetterRTPAddons.addons.magicStick.cmds.MagicStickCommand;
import me.SuperRonanCraft.BetterRTPAddons.util.Files;
import org.bukkit.Bukkit;
import org.bukkit.Material;
Expand All @@ -25,7 +22,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;

public class MagicStickEvents implements Listener {

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>me.SuperRonanCraft</groupId>
<artifactId>BetterRTP</artifactId>
<packaging>jar</packaging>
<version>3.6.9-2-DEV</version>
<version>3.6.10-DEV</version>

<!-- Upload patches to https://repo.ronanplugins.com/#/ -->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package me.SuperRonanCraft.BetterRTP.player.commands.types;

import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandType;
import me.SuperRonanCraft.BetterRTP.player.commands.Commands;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandHelpable;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_PlayerInfo;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_TYPE;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
import me.SuperRonanCraft.BetterRTP.references.PermissionNode;
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP;
import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP_Info;
import me.SuperRonanCraft.BetterRTP.references.messages.Message_RTP;
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesCore;
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesHelp;
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesUsage;
Expand All @@ -32,25 +29,30 @@ public String getName() {
//rtp player <world> <biome1> <biome2...>
public void execute(CommandSender sendi, String label, String[] args) {
if (args.length == 2)
if (Bukkit.getPlayer(args[1]) != null && Bukkit.getPlayer(args[1]).isOnline())
if (Bukkit.getPlayer(args[1]) != null && Bukkit.getPlayer(args[1]).isOnline()) {
HelperRTP.tp(Bukkit.getPlayer(args[1]),
sendi,
Bukkit.getPlayer(args[1]).getWorld(),
null,
RTP_TYPE.FORCED,
false,
false,
null,
new RTP_PlayerInfo(false, false));
else if (Bukkit.getPlayer(args[1]) != null)
new RTP_PlayerInfo());
} else if (Bukkit.getPlayer(args[1]) != null)
MessagesCore.NOTONLINE.send(sendi, args[1]);
else
usage(sendi, label);
else if (args.length >= 3)
if (Bukkit.getPlayer(args[1]) != null && Bukkit.getPlayer(args[1]).isOnline()) {
World world = Bukkit.getWorld(args[2]);
RTP_PlayerInfo playerInfo = getFlags(args);
if (world != null) {
HelperRTP.tp(Bukkit.getPlayer(args[1]), sendi, world, HelperRTP_Info.getBiomes(args, 3, sendi), RTP_TYPE.FORCED);
HelperRTP.tp(Bukkit.getPlayer(args[1]),
sendi,
world,
null,
RTP_TYPE.FORCED,
null,
playerInfo);
} else
MessagesCore.NOTEXIST.send(sendi, args[2]);
} else if (Bukkit.getPlayer(args[1]) != null)
Expand All @@ -61,6 +63,31 @@ else if (args.length >= 3)
usage(sendi, label);
}

private RTP_PlayerInfo getFlags(String[] args) {
boolean applyDelay = true;
boolean applyCooldown = true;
boolean checkCooldown = true;
boolean takeMoney = true;
boolean takeHunger = true;

if (args.length > 3) {
for (int i = 3; i < args.length; i++) {
for (RTP_PlayerInfo.RTP_PLAYERINFO_FLAG flag : RTP_PlayerInfo.RTP_PLAYERINFO_FLAG.values()) {
if (flag.name().equalsIgnoreCase(args[i])) {
switch (flag) {
case NODELAY: applyDelay = false; break;
case NOCOOLDOWN: checkCooldown = false; break;
case IGNORECOOLDOWN: applyCooldown = false; break;
case IGNOREMONEY: takeMoney = false; break;
case IGNOREHUNGER: takeHunger = false; break;
}
}
}
}
}
return new RTP_PlayerInfo(applyDelay, applyCooldown, checkCooldown, takeMoney, takeHunger);
}

public List<String> tabComplete(CommandSender sendi, String[] args) {
List<String> list = new ArrayList<>();
if (args.length == 2) {
Expand All @@ -72,8 +99,11 @@ public List<String> tabComplete(CommandSender sendi, String[] args) {
if (w.getName().startsWith(args[2]) && !BetterRTP.getInstance().getRTP().getDisabledWorlds().contains(w.getName()))
list.add(w.getName());
} else if (args.length > 3) {
if (PermissionNode.BIOME.check(sendi))
HelperRTP_Info.addBiomes(list, args);
for (RTP_PlayerInfo.RTP_PLAYERINFO_FLAG flag : RTP_PlayerInfo.RTP_PLAYERINFO_FLAG.values()) {
if (flag.name().toLowerCase().startsWith(args[args.length - 1].toLowerCase())) {
list.add(flag.name());
}
}
}
return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ public void start(WorldPlayer pWorld) {
if (setup.isCancelled())
return;
// Second Economy check
if (!getPl().getEco().hasBalance(pWorld.getSendi(), pWorld)) {
if (pWorld.getPlayerInfo().takeMoney && !getPl().getEco().hasBalance(pWorld.getSendi(), pWorld)) {
MessagesCore.FAILED_PRICE.send(pWorld.getSendi());
return;
}
if (!getPl().getEco().hasHunger(pWorld.getSendi(), pWorld)) {
if (pWorld.getPlayerInfo().takeHunger && !getPl().getEco().hasHunger(pWorld.getSendi(), pWorld)) {
MessagesCore.FAILED_HUNGER.send(pWorld.getSendi());
return;
}
Expand All @@ -103,7 +103,7 @@ private void rtp(CommandSender sendi, WorldPlayer pWorld, RTP_TYPE type) {
//Setup player rtp methods
RTPPlayer rtpPlayer = new RTPPlayer(p, this, pWorld, type);
// Delaying? Else, just go
if (getPl().getSettings().isDelayEnabled() && pWorld.getPlayerInfo().isApplyDelay()) {
if (pWorld.getPlayerInfo().isApplyDelay() && getPl().getSettings().isDelayEnabled()) {
new RTPDelay(sendi, rtpPlayer, delayTime, cancelOnMove, cancelOnDamage);
} else {
if (!teleport.beforeTeleportInstant(sendi, p))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void attempt(CommandSender sendi, Location loc) {
//Valid location?
if (tpLoc != null && checkDepends(tpLoc)) {
tpLoc.add(0.5, 0, 0.5); //Center location
if (getPl().getEco().charge(player, worldPlayer)) {
if (worldPlayer.getPlayerInfo().isTakeMoney() && getPl().getEco().charge(player, worldPlayer)) {
tpLoc.setYaw(player.getLocation().getYaw());
tpLoc.setPitch(player.getLocation().getPitch());
AsyncHandler.sync(() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public class RTP_PlayerInfo {
takeMoney,
takeHunger;

public RTP_PlayerInfo() {
this(true, true, true, true, true);
}

public RTP_PlayerInfo(boolean applyDelay, boolean applyCooldown) {
this.applyDelay = applyDelay;
this.applyCooldown = applyCooldown;
Expand All @@ -29,4 +33,8 @@ public RTP_PlayerInfo(boolean applyDelay,
this.takeHunger = takeHunger;
}

public enum RTP_PLAYERINFO_FLAG {
NODELAY, NOCOOLDOWN, IGNORECOOLDOWN, IGNOREMONEY, IGNOREHUNGER;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public boolean charge(CommandSender sendi, WorldPlayer pWorld) {
MessagesCore.FAILED_PRICE.send(sendi, pWorld.getPrice());
if (took_food)
player.setFoodLevel(player.getFoodLevel() + hunger);
} else
pWorld.eco_money_taken = true;
} //else
//pWorld.eco_money_taken = true;
return passed_economy;
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,51 @@
public class HelperRTP {

//Teleported and Sender are the same
public static void tp(Player player, World world, List<String> biomes, RTP_TYPE rtpType) {
public static void tp(Player player,
World world,
List<String> biomes,
RTP_TYPE rtpType) {
tp(player, player, world, biomes, rtpType);
}

//Teleported and Sender MAY be different
public static void tp(Player player, CommandSender sendi, World world, List<String> biomes, RTP_TYPE rtpType) {
public static void tp(Player player,
CommandSender sendi,
World world,
List<String> biomes,
RTP_TYPE rtpType) {
tp(player, sendi, world, biomes, rtpType, false, false);
}

//
public static void tp(Player player, CommandSender sendi, World world, List<String> biomes, RTP_TYPE rtpType,
boolean ignoreCooldown, boolean ignoreDelay) {
public static void tp(Player player,
CommandSender sendi,
World world,
List<String> biomes,
RTP_TYPE rtpType,
boolean ignoreCooldown,
boolean ignoreDelay) {
tp(player, sendi, world, biomes, rtpType, ignoreCooldown, ignoreDelay, null);
}

public static void tp(@NotNull Player player, CommandSender sendi, @Nullable World world, List<String> biomes, RTP_TYPE rtpType,
boolean ignoreCooldown, boolean ignoreDelay, @Nullable WorldLocation location) {
world = getActualWorld(player, world, location);
RTPSetupInformation setup_info = new RTPSetupInformation(
world,
sendi,
player,
true,
biomes,
rtpType,
location,
new RTP_PlayerInfo(
!ignoreDelay && HelperRTP_Check.applyDelay(player, sendi),
!ignoreCooldown && HelperRTP_Check.applyCooldown(sendi, player))
);
tp(player, sendi, ignoreCooldown, ignoreDelay, setup_info);
public static void tp(@NotNull Player player,
CommandSender sendi,
@Nullable World world,
List<String> biomes,
RTP_TYPE rtpType,
boolean ignoreCooldown,
boolean ignoreDelay,
@Nullable WorldLocation location) {
tp(player, sendi, world, biomes, rtpType, location, new RTP_PlayerInfo(!ignoreDelay, !ignoreCooldown));
}

public static void tp(@NotNull Player player, CommandSender sendi, @Nullable World world, List<String> biomes, RTP_TYPE rtpType,
boolean ignoreCooldown, boolean ignoreDelay, @Nullable WorldLocation location, RTP_PlayerInfo playerInfo) {
public static void tp(@NotNull Player player,
CommandSender sendi,
@Nullable World world,
List<String> biomes,
RTP_TYPE rtpType,
@Nullable WorldLocation location,
RTP_PlayerInfo playerInfo) {
world = getActualWorld(player, world, location);
RTPSetupInformation setup_info = new RTPSetupInformation(
world,
Expand All @@ -68,13 +78,15 @@ public static void tp(@NotNull Player player, CommandSender sendi, @Nullable Wor
location,
playerInfo
);
tp(player, sendi, ignoreCooldown, ignoreDelay, setup_info);
tp(player, sendi, setup_info);
}

public static void tp(@NotNull Player player, CommandSender sendi, boolean ignoreCooldown, boolean ignoreDelay, RTPSetupInformation setup_info) {
public static void tp(@NotNull Player player,
CommandSender sendi,
RTPSetupInformation setup_info) {
//RTP request cancelled reason
WorldPlayer pWorld = getPlayerWorld(setup_info);
RTP_ERROR_REQUEST_REASON cantReason = HelperRTP_Check.canRTP(player, sendi, pWorld, ignoreCooldown);
RTP_ERROR_REQUEST_REASON cantReason = HelperRTP_Check.canRTP(player, sendi, pWorld, setup_info.getPlayerInfo());
if (cantReason != null) {
String msg = cantReason.getMsg().get(player, null);
if (cantReason == RTP_ERROR_REQUEST_REASON.COOLDOWN) {
Expand All @@ -93,7 +105,9 @@ private static BetterRTP getPl() {
return BetterRTP.getInstance();
}

public static World getActualWorld(Player player, World world, @Nullable WorldLocation location) {
public static World getActualWorld(Player player,
World world,
@Nullable WorldLocation location) {
if (world == null)
world = player.getWorld();
if (location != null)
Expand All @@ -108,7 +122,8 @@ public static World getActualWorld(Player player, World world) {
}

@Nullable
public static WorldLocation getRandomLocation(CommandSender sender, World world) {
public static WorldLocation getRandomLocation(CommandSender sender,
World world) {
HashMap<String, RTPWorld> locations_permissible = CmdLocation.getLocations(sender, world);
if (!locations_permissible.isEmpty()) {
List<String> valuesList = new ArrayList<>(locations_permissible.keySet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_ERROR_REQUEST_REASON;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_PlayerInfo;
import me.SuperRonanCraft.BetterRTP.references.PermissionCheck;
import me.SuperRonanCraft.BetterRTP.references.PermissionNode;
import me.SuperRonanCraft.BetterRTP.references.messages.MessagesCore;
Expand All @@ -13,7 +14,7 @@

public class HelperRTP_Check {

public static RTP_ERROR_REQUEST_REASON canRTP(Player player, CommandSender sendi, WorldPlayer pWorld, boolean ignoreCooldown) {
public static RTP_ERROR_REQUEST_REASON canRTP(Player player, CommandSender sendi, WorldPlayer pWorld, RTP_PlayerInfo rtpInfo) {
if (isRTPing(player)) { //Is RTP'ing
return RTP_ERROR_REQUEST_REASON.IS_RTPING;
}
Expand All @@ -25,12 +26,12 @@ public static RTP_ERROR_REQUEST_REASON canRTP(Player player, CommandSender sendi
if (getPl().getRTP().getDisabledWorlds().contains(pWorld.getWorld().getName())) {
return RTP_ERROR_REQUEST_REASON.WORLD_DISABLED;
}
if (sendi == player && isCoolingDown(sendi, player, pWorld)) { //Is Cooling down
if (rtpInfo.isCheckCooldown() && sendi == player && isCoolingDown(sendi, player, pWorld)) { //Is Cooling down
return RTP_ERROR_REQUEST_REASON.COOLDOWN;
}
if (!getPl().getEco().hasBalance(sendi, pWorld))
if (rtpInfo.isTakeMoney() && !getPl().getEco().hasBalance(sendi, pWorld))
return RTP_ERROR_REQUEST_REASON.PRICE_ECONOMY;
if (!getPl().getEco().hasHunger(sendi, pWorld))
if (rtpInfo.isTakeHunger() && !getPl().getEco().hasHunger(sendi, pWorld))
return RTP_ERROR_REQUEST_REASON.PRICE_HUNGER;
return null;
}
Expand Down

0 comments on commit 0203c28

Please sign in to comment.