Skip to content

Commit

Permalink
Added EnderPearlCooldowns and Anti Vehicle Phasing
Browse files Browse the repository at this point in the history
  • Loading branch information
Driftay committed Aug 9, 2021
1 parent 9f034db commit 9269e82
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/java/com/massivecraft/factions/util/Cooldown.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public static void setCooldown(Faction fac, String name, int seconds) {
}
}

public static String sendCooldownLeft(Player player, String name) {
if (player.hasMetadata(name) || player.getMetadata(name).size() > 0) {
long remaining = player.getMetadata(name).get(0).asLong() - System.currentTimeMillis();
int remainSec = (int) (remaining / 1000L);
return TimeUtil.formatSeconds(remainSec);
}
return "";
}


public static boolean isOnCooldown(Player player, String name) {
if (!player.hasMetadata(name) || player.getMetadata(name).size() <= 0) return false;
long time = player.getMetadata(name).get(0).asLong();
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/massivecraft/factions/util/TimeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ public class TimeUtil {

public static Calendar calender = getCalenderTimeZone();


public static String formatSeconds(int timeInSeconds) {
int hours = timeInSeconds / 3600;
int secondsLeft = timeInSeconds - hours * 3600;
int minutes = secondsLeft / 60;
int seconds = secondsLeft - minutes * 60;
String formattedTime = "";
if (hours < 10)
formattedTime = formattedTime + "0";
formattedTime = formattedTime + hours + ":";
if (minutes < 10)
formattedTime = formattedTime + "0";
formattedTime = formattedTime + minutes + ":";
if (seconds < 10)
formattedTime = formattedTime + "0";
formattedTime = formattedTime + seconds;
return formattedTime;
}

public static String formatDifference(long time) {
if (time == 0L) {
return "Never";
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/massivecraft/factions/zcore/util/TL.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ public enum TL {
DISCORD_CODE_INVALID_KEY("That code is invalid, verify the code is correct."),
DISCORD_CODE_INVALID_FORMAT("If you are submitting a code please only type the code. Example message: 0000"),

ENDER_PEARL_COOLDOWN("&c&l[!] &cYou may enderpearl again in &b{seconds} seconds&c!"),
VEHICLE_TELEPORT_BLOCK("&c&l[!] You cannot teleport while you are inside a vehicle"),


COMMAND_DEINVITE_CANDEINVITE("&c&l[!]&7 Players you can &cdeinvite: "),
COMMAND_DEINVITE_CLICKTODEINVITE("&c&l[!]&7 Click to &crevoke&7 invite for &c%1$s"),
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/pw/saber/corex/CoreX.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ public static void init() {
FactionsPlugin.getInstance().getServer().getPluginManager().registerEvents(new AntiEndPortal(), FactionsPlugin.getInstance());
}

if(getConfig().fetchBoolean("Features.EnderPearl-Cooldown")) {
FactionsPlugin.getInstance().getServer().getPluginManager().registerEvents(new EnderPearlCooldown(), FactionsPlugin.getInstance());
}

if(getConfig().fetchBoolean("Features.Anti-Vehicle-Teleport")) {
FactionsPlugin.getInstance().getServer().getPluginManager().registerEvents(new AntiVehicleTeleport(), FactionsPlugin.getInstance());

}

//if(getConfig().fetchBoolean("Features.Use-Chunkbusters")) {
// FactionsPlugin.getInstance().getServer().getPluginManager().registerEvents(new ChunkBusterListener(), FactionsPlugin.getInstance());
// FactionsPlugin.getInstance().getCommand("chunkbuster").setExecutor(new CommandChunkbuster());
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/pw/saber/corex/listeners/AntiVehicleTeleport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package pw.saber.corex.listeners;

import com.massivecraft.factions.util.CC;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerTeleportEvent;

public class AntiVehicleTeleport implements Listener {

@EventHandler
public void onVehicleExit(PlayerTeleportEvent e){
Player player = e.getPlayer();
if(player.getVehicle() == null) return;

if (player.isInsideVehicle()) {
player.sendMessage(CC.translate(TL.VEHICLE_TELEPORT_BLOCK.toString()));
e.setCancelled(true);
}
}
}
35 changes: 35 additions & 0 deletions src/main/java/pw/saber/corex/listeners/EnderPearlCooldown.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package pw.saber.corex.listeners;

import com.cryptomorin.xseries.XMaterial;
import com.massivecraft.factions.util.CC;
import com.massivecraft.factions.util.Cooldown;
import com.massivecraft.factions.util.TimeUtil;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import pw.saber.corex.CoreX;

import javax.swing.*;

public class EnderPearlCooldown implements Listener {


@EventHandler
public void onPearl(PlayerInteractEvent e){
Action action = e.getAction();
Player player = e.getPlayer();
if(action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK && e.getItem() != null && e.getItem().getType() == XMaterial.ENDER_PEARL.parseMaterial()) {
if(Cooldown.isOnCooldown(player, "enderPearlCooldown")) {
e.setCancelled(true);
long remaining = player.getMetadata("enderPearlCooldown").get(0).asLong() - System.currentTimeMillis();
int remainSec = (int) (remaining / 1000L);
e.getPlayer().sendMessage(CC.translate(TL.ENDER_PEARL_COOLDOWN.toString().replace("{seconds}", TimeUtil.formatSeconds(remainSec))));
} else {
Cooldown.setCooldown(player, "enderPearlCooldown", CoreX.getConfig().fetchInt("Cooldowns.EnderPearl"));
}
}
}
}
5 changes: 4 additions & 1 deletion src/main/resources/corex/corex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#<-------------------------------------->NOTES<-------------------------------------->#

Features:
Use-Chunkbusters: true #Allows For Chunkbuster Placement on the server!
Anti-Vehicle-Teleport: true #Denies Block Phasing Through Exiting Vehicles!
EnderPearl-Cooldown: false #Places a Cooldown on Ender Pearls!
Anti-Nether-Portal: false #Denies players teleporting from nether portals
Anti-End-Portal: false #Denies players teleporting from end portals
No-Cursor-Drop: true #When a player closes their inventory whilst a item is on their cursor it does not drop on the ground it goes back into their inventory
Expand Down Expand Up @@ -40,6 +41,8 @@ Features:
AntiSpawnerMine:
Radius: 20.0 # Radius that the player will be denied mining spawners when an enemy is near.

Cooldowns:
EnderPearl: 15

Chunkbuster:
Run-Async: true
Expand Down

0 comments on commit 9269e82

Please sign in to comment.