Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
cheezychicken authored Aug 5, 2021
1 parent 2fa2d49 commit 07eb61d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
14 changes: 5 additions & 9 deletions src/main/java/com/cheezychicken/pvptoggle/NerdBoardHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,18 @@ private Team getOrCreateTeam(String name) {

// ------------------------------------------------------------------------
/**
* Assign the player to the Team that corresponds to its vanish and modmode
* states, and then update their scoreboard if necessary.
* Assign the player to the Team that corresponds to its pvp
* state, and then update their scoreboard if necessary.
*
* The Team controls the name tag prefix (colour) and collision detection
* between players.
* The Team controls the name tag prefix (colour)
*
* @param player the player.
* @return
* @return
*/
public static void checkPvPstate(Player player) {
boolean inPvPmode = PvPToggle.isActive(player);
Team team = inPvPmode ? _pvpTeam
: _defaultTeam;
_nerdBoard.addPlayerToTeam(team, player);
Bukkit.getServer().broadcastMessage("pvp state checked");
if (player.getScoreboard() != _scoreboard) {
player.setScoreboard(_scoreboard);
}
Expand All @@ -115,11 +111,11 @@ public static void checkPvPstate(Player player) {
*
* @param bool the boolean.
* @return the translated OptionStatus.
*/
*
private static Team.OptionStatus boolToStatus(boolean bool) {
return bool ? Team.OptionStatus.ALWAYS : Team.OptionStatus.NEVER;
}

*/
/**
* Scoreboard API stuff for colored name tags
*/
Expand Down
34 changes: 25 additions & 9 deletions src/main/java/com/cheezychicken/pvptoggle/PvPToggle.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.cheezychicken.pvptoggle;
import com.sk89q.worldguard.bukkit.protection.events.DisallowedPVPEvent;

import nu.nerd.nerdboard.NerdBoard;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
Expand Down Expand Up @@ -38,15 +40,22 @@ public class PvPToggle extends JavaPlugin implements Listener {
@Override
public void onEnable() {
this.getServer().getPluginManager().registerEvents(this, this);

saveDefaultConfig();

NerdBoard nerdBoard = NerdBoardHook.getNerdBoard();
if (nerdBoard != null) {
new NerdBoardHook(nerdBoard);
} else {
//log("NerdBoard is required. http://github.com/nerdnu/NerdBoard");
getPluginLoader().disablePlugin(this);
return;
}

/** for (String uuidString : getConfig().getStringList("players")) {
* try {
* UUID uuid = UUID.fromString(uuidString);
* ENABLED_PLAYERS.add(uuid);
* log("Loaded serialized player: " + uuidString);
* } catch (IllegalArgumentException e) {
* } catch (IllegalArgumentException e) {y/pvp
* log("Invalid UUID found in config: " + uuidString);
* }
* }
Expand Down Expand Up @@ -84,13 +93,11 @@ public boolean onCommand(CommandSender sender, Command command, String name, Str
if (args.length == 1) {
Player player = (Player) sender;
pvpStatusOn(player, "Player");
NerdBoardHook.checkPvPstate(player);
return true;
// Admins can change other people's
} else if (sender.hasPermission("pvp.others")) {
Player player = Bukkit.getPlayer(args[1]);
pvpStatusOn(player, "Admin");
NerdBoardHook.checkPvPstate(player);
return true;
} else {
return false;
Expand All @@ -100,13 +107,11 @@ public boolean onCommand(CommandSender sender, Command command, String name, Str
if (args.length == 1) {
Player player = (Player) sender;
pvpStatusOff(player, "Player");
NerdBoardHook.checkPvPstate(player);
return true;
// Admins can change other people's
} else if (sender.hasPermission("pvp.others")) {
Player player = Bukkit.getPlayer(args[1]);
pvpStatusOff(player, "Admin");
NerdBoardHook.checkPvPstate(player);
return true;
} else {
return false;
Expand Down Expand Up @@ -148,6 +153,7 @@ private void onPVPDamage(DisallowedPVPEvent event) {
// ------------------------------------------------------------------------------------------------------
/**
* Turn off PvP for a player when they die.
* @param player the player
*/
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
Expand All @@ -160,6 +166,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
// ------------------------------------------------------------------------------------------------------
/**
* Turn off PvP for a player when they log out.
* @param player the player
*/

@EventHandler
Expand All @@ -174,6 +181,7 @@ public void onPlayerLeave(PlayerQuitEvent player) {
// ------------------------------------------------------------------------------------------------------
/**
* Turn off PvP for a player when they are kicked.
* @param player the player
*/

@EventHandler
Expand All @@ -187,13 +195,16 @@ public void onPlayerKick(PlayerKickEvent player) {
// ------------------------------------------------------------------------------------------------------
/**
* Turns the player's hunted status on
*
* @param player the player
* @param reason Reason for change
*/
private void pvpStatusOn(Player player, String reason) {
UUID uuid = player.getUniqueId();
String msg = "";
if (isActive(player)) {
if(reason == "Player") {
player.sendMessage("PvP is already enabled for you!");
}
} else {
if(reason == "Player") {
msg = ChatColor.RED + player.getName() + " has turned their PvP on." + ChatColor.RESET;
Expand All @@ -204,14 +215,16 @@ private void pvpStatusOn(Player player, String reason) {
if (msg != "") {
getServer().broadcastMessage(msg);
}
NerdBoardHook.checkPvPstate(player);
}

}

// ------------------------------------------------------------------------------------------------------
/**
* Turns the player's hunted status off
*
* @param player the player
* @param reason Reason for change
*/

private void pvpStatusOff(Player player, String reason) {
Expand All @@ -227,8 +240,11 @@ private void pvpStatusOff(Player player, String reason) {
if (msg != "") {
getServer().broadcastMessage(msg);
}
NerdBoardHook.checkPvPstate(player);
} else {
if(reason == "Player") {
player.sendMessage("PvP is already disabled for you!");
}
}

}
Expand Down

0 comments on commit 07eb61d

Please sign in to comment.