Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Bugs fixed!
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanGmG authored Feb 3, 2021
1 parent b1d4311 commit f3460fc
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 20 deletions.
15 changes: 0 additions & 15 deletions src/main/java/bryangaming/code/EffectRanks.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,5 @@ public void registerManager() {

public void onDisable() {
getLogger().info("Thx for using this plugin <3");
getDisableMessage();
}

public void getDisableMessage() {
int number = (int)(Math.random() * 2.0 + 1.0);

if (number == 1) {
getLogger().info("Goodbye!");
}
else if (number == 2) {
getLogger().info("See you later!");
}
else {
getLogger().info("You shouldn't watch this..");
}
}
}
6 changes: 5 additions & 1 deletion src/main/java/bryangaming/code/Manager.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package bryangaming.code;

import bryangaming.code.api.EffectsModifyImpl;
import bryangaming.code.debug.DebugLogger;
import net.milkbowl.vault.permission.*;
import bryangaming.code.utils.*;
import bryangaming.code.modules.*;
import bryangaming.code.registry.*;
import org.bukkit.*;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.*;

public class Manager {
Expand All @@ -23,6 +23,8 @@ public class Manager {
private CommandsRegistry commandsRegistry;
private ListenersRegistry listenersRegistry;

private EffectsModifyImpl effectsModifyImpl;

private ConfigManager configManager;

public Manager(final EffectRanks plugin) {
Expand All @@ -44,6 +46,8 @@ public void setup() {

commandsRegistry = new CommandsRegistry(this);
listenersRegistry = new ListenersRegistry(this);

effectsModifyImpl = new EffectsModifyImpl(this);
}

public void setupPermisions() {
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/bryangaming/code/api/EffectsModify.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package bryangaming.code.api;

import org.bukkit.entity.Player;

public interface EffectsModify {


/**
* Activate the effects according the rank that have the player.
*
* @param player The player that will activate his effects.
*
*/

static void giveEffectRank(Player player){

}
}
55 changes: 55 additions & 0 deletions src/main/java/bryangaming/code/api/EffectsModifyImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package bryangaming.code.api;

import bryangaming.code.Manager;
import bryangaming.code.modules.CooldownMethod;
import bryangaming.code.modules.MethodManager;
import bryangaming.code.modules.PowerMethod;
import bryangaming.code.modules.RankMethod;
import bryangaming.code.modules.player.PlayerMessage;
import bryangaming.code.registry.ConfigManager;
import bryangaming.code.utils.Configuration;
import org.bukkit.entity.Player;

public class EffectsModifyImpl implements EffectsModify {

private Manager manager;

private static MethodManager methodManager;
private static ConfigManager files;

public EffectsModifyImpl(Manager manager){
this.manager = manager;
methodManager = manager.getPlayerMethods();
files = manager.getFiles();
}


public static void giveEffectRank(Player player){

RankMethod rankMethod = methodManager.getLoopMethod();
CooldownMethod cooldownMethod = methodManager.getCooldownMethod();
PowerMethod powerMethod = methodManager.getPowerMethod();

PlayerMessage playersender = methodManager.getSender();

Configuration config = files.getConfig();
Configuration messages = files.getMessages();
Configuration commands = files.getCommands();

if (cooldownMethod.playerIsInCooldown(player)) {
playersender.sendMessage(player, messages.getString("error.cooldown.wait-time")
.replace("%time%", cooldownMethod.getTextRankCooldown(player)));
return;
}

if (rankMethod.getPlayerRank(player).equalsIgnoreCase("default") && config.getConfigurationSection("default") == null) {
playersender.sendMessage(player, messages.getString("error.effects.empty-effects"));
return;
}

powerMethod.setPower(player.getUniqueId());
playersender.sendMessage(player, commands.getString("commands.effects.status-on"));
cooldownMethod.putCooldown(player, (System.currentTimeMillis() / 1000) + cooldownMethod.getRankCooldown(player));

}
}
43 changes: 43 additions & 0 deletions src/main/java/bryangaming/code/api/events/EnableEffectsEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package bryangaming.code.api.events;

import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

public class EnableEffectsEvent extends Event implements Cancellable{

private final Player player;
private boolean isCancelled;

public EnableEffectsEvent(Player player){
this.player = player;
this.isCancelled = false;
}

public Player getPlayer() {
return player;
}

@Override
public boolean isCancelled() {
return isCancelled;
}

@Override
public void setCancelled(boolean isCancelled) {
this.isCancelled = isCancelled;
}

private static final HandlerList HANDLERS = new HandlerList();

@Override
public @NotNull HandlerList getHandlers() {
return HANDLERS;
}

public static HandlerList getHandlerList() {
return HANDLERS;
}
}
24 changes: 23 additions & 1 deletion src/main/java/bryangaming/code/commands/PowerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import bryangaming.code.Manager;
import bryangaming.code.EffectRanks;

import bryangaming.code.api.EffectsModify;
import bryangaming.code.api.events.EnableEffectsEvent;
import bryangaming.code.modules.CooldownMethod;
import bryangaming.code.modules.PowerMethod;
import bryangaming.code.modules.RankMethod;
Expand All @@ -14,6 +16,7 @@
import me.fixeddev.commandflow.annotated.annotation.Command;

import me.fixeddev.commandflow.bukkit.annotation.Sender;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;

Expand Down Expand Up @@ -51,13 +54,20 @@ public boolean onCommand(@Sender Player player) {
StringFormat stringFormat = manager.getVariables();

playersender.sendMessage(player, messages.getString("error.unknown-args")
.replace("%usage%", stringFormat.getUsage("effects", "on, off, transfer, list")));
.replace("%usage%", stringFormat.getUsage("effects", "on, off, convert, list")));
return true;
}

@Command(names = "on")
public boolean onOnSubCommand(@Sender Player player) {

EnableEffectsEvent enableEffectsEvent = new EnableEffectsEvent(player);
Bukkit.getPluginManager().callEvent(enableEffectsEvent);

if (enableEffectsEvent.isCancelled()){
return false;
}

RankMethod rankMethod = manager.getPlayerMethods().getLoopMethod();
CooldownMethod cooldownMethod = manager.getPlayerMethods().getCooldownMethod();

Expand All @@ -71,12 +81,24 @@ public boolean onOnSubCommand(@Sender Player player) {
playersender.sendMessage(player, messages.getString("error.effects.empty-effects"));
return true;
}
EffectsModify.giveEffectRank(player);

powerMethod.setPower(player.getUniqueId());
playersender.sendMessage(player, commands.getString("commands.effects.status-on"));
cooldownMethod.putCooldown(player, (System.currentTimeMillis() / 1000) + cooldownMethod.getRankCooldown(player));
return true;
}

@Command(names = "convert")
public boolean onConvertSubCommand(@Sender Player player) {

EnableEffectsEvent enableEffectsEvent = new EnableEffectsEvent(player);
Bukkit.getPluginManager().callEvent(enableEffectsEvent);

if (enableEffectsEvent.isCancelled()){
return false;
}

RankMethod rankMethod = manager.getPlayerMethods().getLoopMethod();
CooldownMethod cooldownMethod = manager.getPlayerMethods().getCooldownMethod();
ConvertPotion convertPotion = manager.getPlayerMethods().getConvertPotion();
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/bryangaming/code/listener/ClickEvent.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package bryangaming.code.listener;

import bryangaming.code.Manager;
import bryangaming.code.api.events.EnableEffectsEvent;
import bryangaming.code.modules.CooldownMethod;
import bryangaming.code.modules.PowerMethod;
import bryangaming.code.modules.RankMethod;
import bryangaming.code.modules.player.PlayerMessage;
import bryangaming.code.utils.Configuration;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -82,6 +84,13 @@ public void onClick(PlayerInteractEvent event){

public void setPower(Player player){

EnableEffectsEvent enableEffectsEvent = new EnableEffectsEvent(player);
Bukkit.getPluginManager().callEvent(enableEffectsEvent);

if (enableEffectsEvent.isCancelled()){
return;
}

CooldownMethod cooldownMethod = manager.getPlayerMethods().getCooldownMethod();

if (cooldownMethod.playerIsInCooldown(player)){
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/bryangaming/code/modules/RankMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public RankMethod(Manager manager) {
}

public Set<String> getRanks() {
ConfigurationSection rankconfig = config.getConfigurationSection("groups.");
ConfigurationSection rankconfig = config.getConfigurationSection("groups");
return rankconfig.getKeys(false);
}

Expand All @@ -38,7 +38,6 @@ public String getPlayerRank(Player player) {
if (!Bukkit.getPluginManager().isPluginEnabled("Vault")){
return "default";
}

if (manager.getPermission() == null){
return "default";
}
Expand All @@ -47,7 +46,7 @@ public String getPlayerRank(Player player) {
return "default";
}

if (config.getString("config.status").equalsIgnoreCase("power")) {
if (config.getString("config.status").equalsIgnoreCase("permission")) {
for (String getrank : getRanks()) {
if (player.hasPermission(getrank)){
return getrank;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/bryangaming/code/registry/CommandsRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ private void createCommandManager() {
commandManager = new BukkitCommandManager("EffectRanks");
commandManager.getTranslator().setProvider(new CustomLanguage(manager));



PartInjector injector = PartInjector.create();

injector.install(new DefaultsModule());
Expand Down

0 comments on commit f3460fc

Please sign in to comment.