magicstick event + flashback msg error and ignores portal rtp

This commit is contained in:
SuperRonanCraft 2020-11-20 00:15:37 -05:00
parent 462b2fa6be
commit 5ce3a43d87
14 changed files with 105 additions and 28 deletions

View File

@ -1,5 +1,6 @@
package me.SuperRonanCraft.BetterRTPAddons.addons.flashback;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_TYPE;
import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_TeleportPostEvent;
import me.SuperRonanCraft.BetterRTPAddons.Addon;
import me.SuperRonanCraft.BetterRTPAddons.util.Files;
@ -32,7 +33,7 @@ public class AddonFlashback implements Addon, Listener {
@Override
public void load() {
Files.FILETYPE file = getFile(Files.FILETYPE.CONFIG);
this.time = file.getConfig().getLong(name + ".Time");
this.time = file.getConfig().getLong(name + ".Timer.Delay");
this.database.load(FlashbackDatabase.Columns.values());
warnings.clear();
@ -67,6 +68,7 @@ public class AddonFlashback implements Addon, Listener {
@EventHandler
void onTeleport(RTP_TeleportPostEvent e) {
System.out.println("Player " + e.getPlayer().getName() + " was rtp'd!");
players.add(new FlashbackPlayer(this, e.getPlayer(), e.getOldLocation(), time));
if (e.getType() != RTP_TYPE.ADDON_PORTAL)
players.add(new FlashbackPlayer(this, e.getPlayer(), e.getOldLocation(), time));
}
}

View File

@ -4,7 +4,7 @@ import me.SuperRonanCraft.BetterRTPAddons.AddonsMessages;
import org.bukkit.command.CommandSender;
public class FlashbackMessages implements AddonsMessages {
private static String preM = "Messages";
private static String preM = "Flashback.";
public void getWarning(CommandSender sendi) {
sms(sendi, getLang().getString(preM + "Warning"));

View File

@ -21,7 +21,7 @@ public class FlashbackPlayer {
}
private Runnable getTimedFlash(Long seconds) {
if (plugin.database.setPlayer(p, oldLoc, System.currentTimeMillis() + (seconds * 1000)))
if (!plugin.database.setPlayer(p, oldLoc, System.currentTimeMillis() + (seconds * 1000)))
p.sendMessage("A Database error has occurred!");
return () -> {
plugin.msgs.getWarning(p);

View File

@ -5,11 +5,13 @@ import me.SuperRonanCraft.BetterRTPAddons.Addon;
import me.SuperRonanCraft.BetterRTPAddons.Main;
import me.SuperRonanCraft.BetterRTPAddons.addons.magicStick.cmds.MagicStickCommand;
import me.SuperRonanCraft.BetterRTPAddons.util.Files;
import org.bukkit.inventory.ItemStack;
public class AddonMagicStick implements Addon {
public MagicStickMessages msgs = new MagicStickMessages();
MagicStickCommand cmd = new MagicStickCommand(this);
public MagicStickEvents events = new MagicStickEvents();
@Override
public boolean isEnabled() {
@ -19,10 +21,11 @@ public class AddonMagicStick implements Addon {
@Override
public void load() {
BetterRTP.getInstance().getCmd().registerCommand(cmd, false);
events.load();
}
@Override
public void unload() {
events.unload();
}
}

View File

@ -0,0 +1,59 @@
package me.SuperRonanCraft.BetterRTPAddons.addons.magicStick;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_TYPE;
import me.SuperRonanCraft.BetterRTPAddons.Main;
import me.SuperRonanCraft.BetterRTPAddons.util.Files;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
public class MagicStickEvents implements Listener {
public ItemStack item;
boolean take;
void load() {
Bukkit.getPluginManager().registerEvents(this, Main.getInstance());
Files.FILETYPE file = Main.getInstance().getFiles().getType(Files.FILETYPE.CONFIG);
String title = file.getString("MagicStick.Item.Name");
Material mat = Material.valueOf(file.getString("MagicStick.Item.Material").toUpperCase());
List<String> lore = file.getStringList("MagicStick.Item.Lore");
item = new ItemStack(mat);
ItemMeta meta = item.getItemMeta();
assert meta != null;
meta.setDisplayName(BetterRTP.getInstance().getText().color(title));
meta.setLore(lore);
lore.forEach((str) -> {lore.set(lore.indexOf(str), BetterRTP.getInstance().getText().color(str)); });
item.setItemMeta(meta);
this.take = file.getBoolean("MagicStick.Take");
}
void unload() {
HandlerList.unregisterAll(this);
}
@EventHandler
void use(PlayerInteractEvent e) {
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
ItemStack eItem = e.getItem();
if (eItem != null && eItem.getType() == item.getType()) {
if (Objects.equals(eItem.getItemMeta(), item.getItemMeta())) {
BetterRTP.getInstance().getCmd().tp(e.getPlayer(), e.getPlayer(), e.getPlayer().getWorld().getName(), null, RTP_TYPE.ADDON);
}
}
}
}
}

View File

@ -4,11 +4,13 @@ import me.SuperRonanCraft.BetterRTPAddons.addons.magicStick.AddonMagicStick;
import me.SuperRonanCraft.BetterRTPAddons.addons.portals.AddonPortals;
import me.SuperRonanCraft.BetterRTPAddons.addons.portals.region.PortalsRegionInfo;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class MagicStickCommand_Give implements MagicStickCommands {
@Override
public void execute(CommandSender sendi, String label, String[] args, AddonMagicStick addon) {
sendi.sendMessage("magicstick give command!");
Player p = (Player) sendi;
p.getWorld().dropItem(p.getLocation(), addon.events.item.clone());
}
}

View File

@ -56,7 +56,7 @@ public class PortalsEvents implements Listener {
&& ploc.getBlockY() >= Math.min(loc1.getBlockY(), loc2.getBlockY())) {
playerPortaling.put(e.getPlayer(), portal);
BetterRTP.getInstance().getCmd().tp(e.getPlayer(), e.getPlayer(),
e.getPlayer().getWorld().getName(), null, RTP_TYPE.ADDON, ignoreCooldown, ignoreDelay);
e.getPlayer().getWorld().getName(), null, RTP_TYPE.ADDON_PORTAL, ignoreCooldown, ignoreDelay);
return;
}
}

View File

@ -14,7 +14,7 @@ public class PlayerInfo {
private final HashMap<Player, RTP_INV_SETTINGS> invType = new HashMap<>();
private final HashMap<Player, World> invWorld = new HashMap<>();
private final HashMap<Player, RTP_INV_SETTINGS> invNextInv = new HashMap<>();
private final HashMap<Player, RTP_TYPE> rtpType = new HashMap<>();
//private final HashMap<Player, RTP_TYPE> rtpType = new HashMap<>();
public Inventory getInv(Player p) {
return invs.get(p);
@ -32,9 +32,9 @@ public class PlayerInfo {
return invNextInv.get(p);
}
public RTP_TYPE getRTPType(Player p) {
return rtpType.getOrDefault(p, RTP_TYPE.COMMAND);
}
//public RTP_TYPE getRTPType(Player p) {
// return rtpType.getOrDefault(p, RTP_TYPE.COMMAND);
//}
public void setInv(Player p, Inventory inv) {
invs.put(p, inv);
@ -52,9 +52,9 @@ public class PlayerInfo {
invNextInv.put(p, type);
}
public void setRTPType(Player p, RTP_TYPE rtpType) {
this.rtpType.put(p, rtpType);
}
//public void setRTPType(Player p, RTP_TYPE rtpType) {
// this.rtpType.put(p, rtpType);
//}
//--Logic--

View File

@ -3,6 +3,7 @@ package me.SuperRonanCraft.BetterRTP.player.commands.types;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommandHelpable;
import me.SuperRonanCraft.BetterRTP.player.commands.RTPCommand;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_TYPE;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -19,7 +20,7 @@ public class CmdTest implements RTPCommand, RTPCommandHelpable {
public void execute(CommandSender sendi, String label, String[] args) {
if (sendi instanceof Player) {
Player p = (Player) sendi;
BetterRTP.getInstance().getRTP().getTeleport().afterTeleport(p, p.getLocation(), 0, 0, p.getLocation());
BetterRTP.getInstance().getRTP().getTeleport().afterTeleport(p, p.getLocation(), 0, 0, p.getLocation(), RTP_TYPE.COMMAND);
} else
sendi.sendMessage("Console is not able to execute this command! Try '/rtp help'");
}

View File

@ -167,17 +167,17 @@ public class RTP {
// Economy
if (!getPl().getEco().hasBalance(sendi, pWorld))
return;
BetterRTP.getInstance().getpInfo().setRTPType(p, rtpType);
rtp(sendi, pWorld, delay);
//BetterRTP.getInstance().getpInfo().setRTPType(p, rtpType);
rtp(sendi, pWorld, delay, rtpType);
}
private void rtp(CommandSender sendi, WorldPlayer pWorld, boolean delay) {
private void rtp(CommandSender sendi, WorldPlayer pWorld, boolean delay, RTP_TYPE type) {
//Cooldown
Player p = pWorld.getPlayer();
getPl().getCmd().cooldowns.add(p.getUniqueId());
getPl().getCmd().rtping.put(p.getUniqueId(), true); //Cache player so they cant run '/rtp' again while rtp'ing
//Setup player rtp methods
RTPPlayer rtp = new RTPPlayer(p, this, pWorld);
RTPPlayer rtp = new RTPPlayer(p, this, pWorld, type);
// Delaying? Else, just go
if (getPl().getSettings().delayEnabled && delay) {
new RTPDelay(sendi, rtp, delayTime, cancelOnMove, cancelOnDamage);

View File

@ -18,11 +18,13 @@ public class RTPPlayer {
private final Player p;
private final RTP settings;
WorldPlayer pWorld;
RTP_TYPE type;
RTPPlayer(Player p, RTP settings, WorldPlayer pWorld) {
RTPPlayer(Player p, RTP settings, WorldPlayer pWorld, RTP_TYPE type) {
this.p = p;
this.settings = settings;
this.pWorld = pWorld;
this.type = type;
}
public Player getPlayer() {
@ -50,7 +52,7 @@ public class RTPPlayer {
//Valid location?
if (tpLoc != null && checkDepends(tpLoc)) {
if (getPl().getEco().charge(p, pWorld)) {
settings.teleport.sendPlayer(sendi, p, tpLoc, pWorld.getPrice(), pWorld.getAttempts());
settings.teleport.sendPlayer(sendi, p, tpLoc, pWorld.getPrice(), pWorld.getAttempts(), type);
}
} else
randomlyTeleport(sendi);

View File

@ -42,7 +42,7 @@ public class RTPTeleport {
// }
void sendPlayer(final CommandSender sendi, final Player p, final Location location, final int price,
final int attempts) throws NullPointerException {
final int attempts, RTP_TYPE type) throws NullPointerException {
Location oldLoc = p.getLocation();
loadingTeleport(p, sendi); //Send loading message to player who requested
List<CompletableFuture<Chunk>> asyncChunks = getChunks(location); //Get a list of chunks
@ -58,12 +58,12 @@ public class RTPTeleport {
PaperLib.teleportAsync(p, loc).thenRun(new BukkitRunnable() { //Async teleport
@Override
public void run() {
afterTeleport(p, loc, price, attempts, oldLoc);
afterTeleport(p, loc, price, attempts, oldLoc, type);
if (sendi != p) //Tell player who requested that the player rtp'd
sendSuccessMsg(sendi, p.getName(), loc, price, false, attempts);
getPl().getCmd().rtping.remove(p.getUniqueId()); //No longer rtp'ing
//Save respawn location if first join
if (BetterRTP.getInstance().getpInfo().getRTPType(p) == RTP_TYPE.JOIN) //RTP Type was Join
if (type == RTP_TYPE.JOIN) //RTP Type was Join
if (BetterRTP.getInstance().getSettings().rtpOnFirstJoin_SetAsRespawn) //Save as respawn is enabled
p.setBedSpawnLocation(loc, true); //True means to force a respawn even without a valid bed
}
@ -79,14 +79,14 @@ public class RTPTeleport {
//Effects
public void afterTeleport(Player p, Location loc, int price, int attempts, Location oldLoc) { //Only a successful rtp should run this OR '/rtp test'
public void afterTeleport(Player p, Location loc, int price, int attempts, Location oldLoc, RTP_TYPE type) { //Only a successful rtp should run this OR '/rtp test'
eSounds.playTeleport(p);
eParticles.display(p);
ePotions.giveEffects(p);
eTitles.showTitle(RTPTitles.RTP_TITLE_TYPE.TELEPORT, p, loc, attempts, 0);
if (eTitles.sendMsg(RTPTitles.RTP_TITLE_TYPE.TELEPORT))
sendSuccessMsg(p, p.getName(), loc, price, true, attempts);
getPl().getServer().getPluginManager().callEvent(new RTP_TeleportPostEvent(p, loc, oldLoc));
getPl().getServer().getPluginManager().callEvent(new RTP_TeleportPostEvent(p, loc, oldLoc, type));
}
public void beforeTeleportInstant(CommandSender sendi, Player p) {

View File

@ -4,5 +4,6 @@ public enum RTP_TYPE {
COMMAND, //Player executed command
FORCED, //Player was forced to rtp (/rtp player <player>)
JOIN, //Player joined and was rtp'd automatically
ADDON //Player RTP'd from the external addons plugin
ADDON, //Player RTP'd from the external addons plugin
ADDON_PORTAL //Player RTP'd from the external addons (Portals)
}

View File

@ -1,5 +1,6 @@
package me.SuperRonanCraft.BetterRTP.references.customEvents;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_TYPE;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@ -10,12 +11,14 @@ public class RTP_TeleportPostEvent extends Event {
Player p;
Location loc;
Location oldLoc;
RTP_TYPE type;
private static final HandlerList handler = new HandlerList();
public RTP_TeleportPostEvent(Player p, Location loc, Location oldLoc) {
public RTP_TeleportPostEvent(Player p, Location loc, Location oldLoc, RTP_TYPE type) {
this.p = p;
this.loc = loc;
this.oldLoc = oldLoc;
this.type = type;
}
public Player getPlayer() {
@ -38,4 +41,8 @@ public class RTP_TeleportPostEvent extends Event {
public static HandlerList getHandlerList() {
return handler;
}
public RTP_TYPE getType() {
return type;
}
}