-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
238 additions
and
39 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
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,60 @@ | ||
package com.elikill58.ipmanager.ban; | ||
|
||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.OfflinePlayer; | ||
|
||
public class Ban { | ||
|
||
private final UUID playerId; | ||
private final String reason; | ||
private final String bannedBy; | ||
|
||
public Ban(UUID playerId, String reason, String bannedBy) { | ||
this.playerId = playerId; | ||
this.reason = reason; | ||
this.bannedBy = bannedBy; | ||
} | ||
|
||
public UUID getPlayerId() { | ||
return playerId; | ||
} | ||
|
||
public OfflinePlayer getOfflinePlayer() { | ||
return Bukkit.getOfflinePlayer(getPlayerId()); | ||
} | ||
|
||
public String getReason() { | ||
return reason; | ||
} | ||
|
||
public String getBannedBy() { | ||
return bannedBy; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
Ban ban = (Ban) o; | ||
return playerId.equals(ban.playerId) && reason.equals(ban.reason) | ||
&& bannedBy.equals(ban.bannedBy); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(playerId, reason, bannedBy); | ||
} | ||
|
||
public static Ban from(Ban from) { | ||
return new Ban(from.getPlayerId(), from.getReason(), from.getBannedBy()); | ||
} | ||
|
||
public static Ban create(UUID playerId, String reason, String bannedBy) { | ||
return new Ban(playerId, reason, bannedBy); | ||
} | ||
} |
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,31 @@ | ||
package com.elikill58.ipmanager.ban; | ||
|
||
import org.bukkit.configuration.ConfigurationSection; | ||
|
||
import com.elikill58.ipmanager.IpManager; | ||
|
||
public class BanManager { | ||
|
||
private static BanManager instance; | ||
public static BanManager getInstance() { | ||
if(instance == null) | ||
instance = new BanManager(IpManager.getInstance().getConfig().getConfigurationSection("ban")); | ||
return instance; | ||
} | ||
|
||
private final BanProcessor processor; | ||
private final ConfigurationSection config; | ||
|
||
public BanManager(ConfigurationSection config) { | ||
this.config = config; | ||
processor = BanProcessor.valueOf(config.getString("processor", "command").toUpperCase()); | ||
} | ||
|
||
public BanProcessor getProcessor() { | ||
return processor; | ||
} | ||
|
||
public String getCommand() { | ||
return config.getString("command"); | ||
} | ||
} |
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,22 @@ | ||
package com.elikill58.ipmanager.ban; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.bukkit.Bukkit; | ||
|
||
public enum BanProcessor { | ||
|
||
COMMAND((ban) -> { | ||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), BanManager.getInstance().getCommand().replaceAll("%uuid%", ban.getPlayerId().toString()).replaceAll("%name%", ban.getOfflinePlayer().getName()).replaceAll("%reason%", ban.getReason())); | ||
}); | ||
|
||
private final Consumer<Ban> call; | ||
|
||
private BanProcessor(Consumer<Ban> call) { | ||
this.call = call; | ||
} | ||
|
||
public void run(Ban ban) { | ||
call.accept(ban); | ||
} | ||
} |
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