Skip to content

Commit

Permalink
Merge pull request #180 from Braekpo1nt/146-fix-damage-done-by-last-f…
Browse files Browse the repository at this point in the history
…ew-days-of-changes-before-mct1

146 fix damage done by last few days of changes before mct1
  • Loading branch information
Braekpo1nt authored Apr 13, 2023
2 parents a6b23a4 + 01f2025 commit f484e82
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 164 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ Required plugins. Read this or you will get errors.

# Running the event

## Participants
In order to host an event, you need to [add participants](#adding-a-new-participant) (the plugin has to know who is a participant and who is an admin).

### Starting a game
You can start a game with the following command:

Expand Down Expand Up @@ -67,6 +64,10 @@ Every participant must be on a team, so you must first have at least one team. T
### Removing a team
You can remove a team entirely. Points are lost and team members are removed, also losing their points, as if you [removed them manually](#removing-a-participant)


## Participants
In order to host an event, you need to [add participants](#adding-a-new-participant) (the plugin has to know who is a participant and who is an admin).

### Adding a new participant
Participants must be on a team, so you must first [add a new team](#adding-a-new-team)

Expand Down Expand Up @@ -103,7 +104,14 @@ You can add, subtract, or set the scores of players and teams with the following
- `add` add the `value`
- `subtract` subtract the `value`
- `set` set the score to the `value`
- `<player|team>` specify player or
- `<player|team>` specify player or team
- `<playerName|teamName>` If you specified `player` above, enter the `playerName` of the player whose score you want to modify. If you specified `team` above, enter the `teamName` of the team whose score you want to modify.
- `<value>` the value you want to `add`/`subtract`/`set`.
- Must be an integer.
- Can be negative for `add`/`subtract`
- If you add a negative number it's subtracted, if you subtract a negative number it's added.
- Must be positive for `set`.
- You can't modify a score so that it's less than 0. If you try to subtract a number from a score that would cause it to go negative, the score is simply set to 0.


## Games List
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/braekpo1nt/mctmanager/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.braekpo1nt.mctmanager.games.GameManager;
import org.braekpo1nt.mctmanager.listeners.BlockEffectsListener;
import org.braekpo1nt.mctmanager.hub.HubBoundaryListener;
import org.braekpo1nt.mctmanager.listeners.MCTDebugListener;
import org.braekpo1nt.mctmanager.listeners.PlayerJoinListener;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -53,7 +52,6 @@ public void onEnable() {
HubBoundaryListener hubBoundaryListener = new HubBoundaryListener(this);
BlockEffectsListener blockEffectsListener = new BlockEffectsListener(this);
new PlayerJoinListener(this, mctScoreboard);
new MCTDebugListener(this);

// Commands
new MCTDebugCommand(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Implement TabExecutor in your sub command to provide tab completion
*/
public abstract class CommandManager implements TabExecutor {

protected final Map<String, CommandExecutor> subCommands = new HashMap<>();

protected abstract Component getUsageMessage();
Expand Down
40 changes: 5 additions & 35 deletions src/main/java/org/braekpo1nt/mctmanager/commands/MCTCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.braekpo1nt.mctmanager.commands;

import net.kyori.adventure.text.Component;
import org.braekpo1nt.mctmanager.Main;
import org.braekpo1nt.mctmanager.commands.game.GameSubCommand;
import org.braekpo1nt.mctmanager.commands.team.TeamSubCommand;
Expand All @@ -24,10 +25,8 @@
* The super command for all MCT related commands.
* Everything should start with /mct _____, where _____ is a sub command
*/
public class MCTCommand implements TabExecutor {
public class MCTCommand extends CommandManager {

private final Map<String, CommandExecutor> subCommands = new HashMap<>();

public MCTCommand(Main plugin, GameManager gameManager, HubBoundaryListener hubBoundaryListener, BlockEffectsListener blockEffectsListener) {
plugin.getCommand("mct").setExecutor(this);
subCommands.put("game", new GameSubCommand(gameManager));
Expand Down Expand Up @@ -55,38 +54,9 @@ public MCTCommand(Main plugin, GameManager gameManager, HubBoundaryListener hubB
});
}


@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length < 1) {
sender.sendMessage("Usage: /mct <option>");
return false;
}
String subCommandName = args[0];
if (!subCommands.containsKey(subCommandName)) {
sender.sendMessage(String.format("Argument %s is not recognized.", subCommandName));
return true;
}

return subCommands.get(subCommandName).onCommand(sender, command, label, Arrays.copyOfRange(args, 1, args.length));
}

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length == 1) {
List<String> subCommandNames = subCommands.keySet().stream().sorted().toList();
return subCommandNames;
}
if (args.length > 1) {
String subCommandName = args[0];
if (!subCommands.containsKey(subCommandName)) {
return null;
}
CommandExecutor subCommand = subCommands.get(subCommandName);
if (subCommand instanceof TabExecutor) {
TabExecutor subTabCommand = ((TabExecutor) subCommand);
return subTabCommand.onTabComplete(sender, command, label, Arrays.copyOfRange(args, 1, args.length));
}
}
return null;
protected Component getUsageMessage() {
return Component.text("Usage: /mct <option>");
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package org.braekpo1nt.mctmanager.commands.game;

import net.kyori.adventure.text.Component;
import org.braekpo1nt.mctmanager.commands.CommandManager;
import org.braekpo1nt.mctmanager.games.GameManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GameSubCommand implements TabExecutor {
public class GameSubCommand extends CommandManager {

private final Map<String, CommandExecutor> subCommands = new HashMap<>();

Expand All @@ -25,37 +20,7 @@ public GameSubCommand(GameManager gameManager) {
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length < 1) {
sender.sendMessage("Usage: /mct game <options>");
return true;
}
String subCommandName = args[0];
if (!subCommands.containsKey(subCommandName)) {
sender.sendMessage(String.format("Argument %s is not recognized.", subCommandName));
return true;
}

return subCommands.get(subCommandName).onCommand(sender, command, label, Arrays.copyOfRange(args, 1, args.length));
}

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length == 1) {
List<String> subCommandNames = subCommands.keySet().stream().sorted().toList();
return subCommandNames;
}
if (args.length > 1) {
String subCommandName = args[0];
if (!subCommands.containsKey(subCommandName)) {
return null;
}
CommandExecutor subCommand = subCommands.get(subCommandName);
if (subCommand instanceof TabExecutor) {
TabExecutor subTabCommand = ((TabExecutor) subCommand);
return subTabCommand.onTabComplete(sender, command, label, Arrays.copyOfRange(args, 1, args.length));
}
}
return null;
protected Component getUsageMessage() {
return Component.text("Usage: /mct game <options>");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.braekpo1nt.mctmanager.commands.team;

import net.kyori.adventure.text.Component;
import org.braekpo1nt.mctmanager.commands.CommandManager;
import org.braekpo1nt.mctmanager.commands.team.score.ScoreSubCommand;
import org.braekpo1nt.mctmanager.games.GameManager;
import org.bukkit.command.Command;
Expand All @@ -14,13 +16,9 @@
import java.util.List;
import java.util.Map;

public class TeamSubCommand implements TabExecutor {

private final GameManager gameManager;
private final Map<String, CommandExecutor> subCommands = new HashMap<>();
public class TeamSubCommand extends CommandManager {

public TeamSubCommand(GameManager gameManager) {
this.gameManager = gameManager;
subCommands.put("add", new AddSubCommand(gameManager));
subCommands.put("join", new JoinSubCommand(gameManager));
subCommands.put("leave", new LeaveSubCommand(gameManager));
Expand All @@ -30,37 +28,7 @@ public TeamSubCommand(GameManager gameManager) {
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length < 1) {
sender.sendMessage("Usage: /mct team <options>");
return true;
}
String subCommandName = args[0];
if (!subCommands.containsKey(subCommandName)) {
sender.sendMessage(String.format("Argument %s is not recognized.", subCommandName));
return true;
}

return subCommands.get(subCommandName).onCommand(sender, command, label, Arrays.copyOfRange(args, 1, args.length));
}

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length == 1) {
List<String> subCommandNames = subCommands.keySet().stream().sorted().toList();
return subCommandNames;
}
if (args.length > 1) {
String subCommandName = args[0];
if (!subCommands.containsKey(subCommandName)) {
return null;
}
CommandExecutor subCommand = subCommands.get(subCommandName);
if (subCommand instanceof TabExecutor) {
TabExecutor subTabCommand = ((TabExecutor) subCommand);
return subTabCommand.onTabComplete(sender, command, label, Arrays.copyOfRange(args, 1, args.length));
}
}
return null;
protected Component getUsageMessage() {
return Component.text("Usage: /mct team <options>");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.braekpo1nt.mctmanager.commands.team.score;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.braekpo1nt.mctmanager.games.GameManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
Expand Down Expand Up @@ -37,14 +38,19 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command

if (!gameManager.isParticipant(offlinePlayer.getUniqueId())) {
sender.sendMessage(Component.text(playerName)
.append(Component.text(" is not a participant")));
.append(Component.text(" is not a participant"))
.color(NamedTextColor.RED));
return true;
}
String scoreString = args[1];
try {
int score = Integer.parseInt(scoreString);
if (invert) {
score = -score;
int currentScore = gameManager.getScore(offlinePlayer.getUniqueId());
if (currentScore + score < 0) {
score = -currentScore;
}
}
gameManager.addScore(offlinePlayer.getUniqueId(), score);
int newScore = gameManager.getScore(offlinePlayer.getUniqueId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
int score = Integer.parseInt(scoreString);
if (invert) {
score = -score;
int currentScore = gameManager.getScore(teamName);
if (currentScore + score < 0) {
score = -currentScore;
}
}
gameManager.addScore(teamName, score);
int newScore = gameManager.getScore(teamName);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/braekpo1nt/mctmanager/games/MCTGames.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public enum MCTGames {
MECHA,
CAPTURE_THE_FLAG,
SPLEEF,
FINAL_GAME, PARKOUR_PATHWAY
FINAL_GAME,
PARKOUR_PATHWAY
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.braekpo1nt.mctmanager.Main;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -18,32 +19,28 @@
*/
public class HubBoundaryListener implements Listener {

private final World hubWorld;
private boolean boundaryEnabled = true;

public HubBoundaryListener(Main plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
MVWorldManager worldManager = Main.multiverseCore.getMVWorldManager();
this.hubWorld = worldManager.getMVWorld("Hub").getCBWorld();
}

/**
* Detects when the player moves out of bounds of the hub, and teleports them back to the starting place
* @param event A player move event
*/
@EventHandler
public void onPlayerOutofBounds(PlayerMoveEvent event) {
public void onPlayerOutOfBounds(PlayerMoveEvent event) {
if (!boundaryEnabled) {
return;
}
Player player = event.getPlayer();
Location loc = player.getLocation();

Plugin multiversePlugin = Bukkit.getPluginManager().getPlugin("Multiverse-Core");
MultiverseCore multiverseCore = ((MultiverseCore) multiversePlugin);
MVWorldManager worldManager = multiverseCore.getMVWorldManager();
MultiverseWorld hubWorld = worldManager.getMVWorld("Hub");
MultiverseWorld playerWorld = worldManager.getMVWorld(player.getWorld());

// make sure the player is in the hub world
if (playerWorld.equals(hubWorld)) {

if (player.getWorld().equals(hubWorld)) {
// check if the player falls below y=130
if (loc.getY() < 130) {
// Teleport player to hub start loc
Expand All @@ -65,14 +62,7 @@ public void onPlayerDamage(EntityDamageEvent event) {
}
Player player = ((Player) event.getEntity());

Plugin multiversePlugin = Bukkit.getPluginManager().getPlugin("Multiverse-Core");
MultiverseCore multiverseCore = ((MultiverseCore) multiversePlugin);
MVWorldManager worldManager = multiverseCore.getMVWorldManager();
MultiverseWorld hubWorld = worldManager.getMVWorld("Hub");
MultiverseWorld playerWorld = worldManager.getMVWorld(player.getWorld());

// make sure the player is in the hub world
if (playerWorld.equals(hubWorld)) {
if (player.getWorld().equals(hubWorld)) {
if (!event.getCause().equals(EntityDamageEvent.DamageCause.LAVA)
|| event.getCause().equals(EntityDamageEvent.DamageCause.FIRE)) {
event.setCancelled(true);
Expand Down

This file was deleted.

0 comments on commit f484e82

Please sign in to comment.