-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removes tps based events Adds player count to hub menu
- Loading branch information
1 parent
986273c
commit a961f9c
Showing
13 changed files
with
531 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/main/java/me/shakeforprotein/treeboteleport/Commands/SetPersonalWarp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package me.shakeforprotein.treeboteleport.Commands; | ||
|
||
import me.shakeforprotein.treeboteleport.TreeboTeleport; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.Location; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.defaults.BukkitCommand; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
|
||
public class SetPersonalWarp { | ||
|
||
private TreeboTeleport pl; | ||
|
||
public SetPersonalWarp(TreeboTeleport main) { | ||
this.pl = main; | ||
} | ||
|
||
public boolean register(String command) { | ||
if (!pl.getConfig().getBoolean("disabledCommands." + command)) { | ||
BukkitCommand item2 = new BukkitCommand(command.toLowerCase()) { | ||
@Override | ||
public boolean execute(CommandSender sender, String label, String[] args) { | ||
this.setDescription("Creates a personal warp point with given name, that is accessible to all other players in this gamemode"); | ||
this.setUsage("/SetPWarp <warp name> - requires tbteleport.player.warps.setpersonalwarp"); | ||
this.setPermission("tbteleport.player.warps.setpersonalwarp"); | ||
if (sender.hasPermission(this.getPermission())) { | ||
|
||
File warpsYml = new File(pl.getDataFolder(), File.separator + "warps.yml"); | ||
if (!warpsYml.exists()) { | ||
sender.sendMessage(pl.err + "Warps data not found. Attempting to recover."); | ||
try { | ||
warpsYml.createNewFile(); | ||
FileConfiguration warps = YamlConfiguration.loadConfiguration(warpsYml); | ||
try { | ||
warps.options().copyDefaults(); | ||
warps.save(warpsYml); | ||
} catch (FileNotFoundException e) { | ||
pl.makeLog(e); | ||
} | ||
} catch (IOException e) { | ||
pl.makeLog(e); | ||
sender.sendMessage(pl.err + "Creating warps file failed"); | ||
} | ||
} | ||
FileConfiguration warps = YamlConfiguration.loadConfiguration(warpsYml); | ||
Player p = (Player) sender; | ||
Location loc = p.getLocation(); | ||
String world = loc.getWorld().getName(); | ||
double x = loc.getX(); | ||
double y = loc.getY(); | ||
double z = loc.getZ(); | ||
float pitch = loc.getPitch(); | ||
float yaw = loc.getYaw(); | ||
if (args.length == 0) { | ||
p.sendMessage(pl.err + "You must provide a name for your new warp"); | ||
} else if (args.length > 2) { | ||
p.sendMessage(pl.err + "Too many arguments"); | ||
} else { | ||
String name = args[0]; | ||
args[0] = args[0].toLowerCase(); | ||
warps.set("playerWarps." + p.getUniqueId().toString() + ".name", name); | ||
warps.set("playerWarps." + p.getUniqueId().toString() + ".world", world); | ||
warps.set("playerWarps." + p.getUniqueId().toString() + ".x", x); | ||
warps.set("playerWarps." + p.getUniqueId().toString() + ".y", y); | ||
warps.set("playerWarps." + p.getUniqueId().toString() + ".z", z); | ||
warps.set("playerWarps." + p.getUniqueId().toString() + ".pitch", pitch); | ||
warps.set("playerWarps." + p.getUniqueId().toString() + ".yaw", yaw); | ||
|
||
try { | ||
warps.save(warpsYml); | ||
p.sendMessage(pl.badge + "Player Warp with name: " + ChatColor.GOLD + args[0] + ChatColor.RESET + " has been saved."); | ||
p.sendMessage("If you choose to set a new PWarp, this warp will be overwritten."); | ||
} catch (IOException e) { | ||
pl.makeLog(e); | ||
p.sendMessage(pl.err + "Saving warps file Unsuccessful"); | ||
} | ||
} | ||
} else { | ||
sender.sendMessage(ChatColor.RED + "You do not have access to this command. You require permission node " + ChatColor.GOLD + this.getPermission()); | ||
} | ||
return true; | ||
} | ||
}; | ||
pl.registerNewCommand(pl.getDescription().getName(), item2); | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerMoveListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,71 @@ | ||
package me.shakeforprotein.treeboteleport.Listeners; | ||
|
||
import me.shakeforprotein.treeboteleport.Bungee.BungeeSend; | ||
import me.shakeforprotein.treeboteleport.TreeboTeleport; | ||
import net.minecraft.server.v1_16_R2.MinecraftServer; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerChangedWorldEvent; | ||
import org.bukkit.event.player.PlayerMoveEvent; | ||
import org.bukkit.event.player.PlayerQuitEvent; | ||
|
||
import java.util.HashMap; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class PlayerMoveListener implements Listener { | ||
|
||
public TreeboTeleport pl; | ||
private HashMap<Player, Long> afkHash = new HashMap<>(); | ||
private HashMap<Player, Location> locationHash = new HashMap<>(); | ||
private BungeeSend bungeeSend; | ||
|
||
public PlayerMoveListener(TreeboTeleport main){ | ||
this.pl = main; | ||
bungeeSend = new BungeeSend(pl); | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerMove(PlayerMoveEvent e){ | ||
if(pl.lockMove.containsKey(e.getPlayer().getUniqueId())){ | ||
e.setTo(e.getFrom()); | ||
} | ||
|
||
if(pl.getConfig().getBoolean("doAfkKick")){ | ||
if(afkHash == null || !afkHash.containsKey(e.getPlayer())){ | ||
afkHash.put(e.getPlayer(), System.currentTimeMillis()); | ||
locationHash.put(e.getPlayer(), e.getTo()); | ||
} else if(e.getPlayer().getWorld() != locationHash.get(e.getPlayer()).getWorld()){ | ||
afkHash.replace(e.getPlayer(), System.currentTimeMillis()); | ||
locationHash.replace(e.getPlayer(), e.getTo()); | ||
} | ||
else{ | ||
Double x, z, x1, x2, z1, z2; | ||
x1 = Math.floor(locationHash.get(e.getPlayer()).getX()); | ||
x2 = Math.floor(e.getTo().getX()); | ||
z1 = Math.floor(locationHash.get(e.getPlayer()).getZ()); | ||
z2 = Math.floor(e.getTo().getZ()); | ||
x = x2 - x1; | ||
z = z1 - z2; | ||
if(Math.abs(x*z) > 1000){ | ||
afkHash.replace(e.getPlayer(), System.currentTimeMillis()); | ||
locationHash.replace(e.getPlayer(), e.getTo()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void playerDisconnect(PlayerQuitEvent e){ | ||
if(afkHash.containsKey(e.getPlayer())){afkHash.remove(e.getPlayer()); | ||
locationHash.remove(e.getPlayer());} | ||
} | ||
|
||
@EventHandler | ||
public void playerChangeWorld(PlayerChangedWorldEvent e){ | ||
afkHash.put(e.getPlayer(), System.currentTimeMillis()); | ||
locationHash.put(e.getPlayer(), e.getPlayer().getLocation()); | ||
} | ||
} |
Oops, something went wrong.