Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.fezzfall.api.others.sanctions;
- import fr.fezzfall.api.bungee.APIBungee;
- import fr.fezzfall.api.bungee.events.PlayerChatBungeeEvent;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.UUID;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import net.md_5.bungee.api.ProxyServer;
- import net.md_5.bungee.api.chat.ComponentBuilder;
- import net.md_5.bungee.api.connection.ProxiedPlayer;
- import org.apache.commons.lang.time.DateUtils;
- import redis.clients.jedis.Jedis;
- public class SanctionManager
- {
- private SanctionType type;
- private String author;
- private String target_name;
- private String target_uuid;
- private Date time;
- private Date endtime;
- private String endtimeString;
- private String reason;
- private boolean result;
- public SanctionManager(SanctionType type, String author, String target_name, String endtime, String reason, boolean targetname)
- {
- String UUID = null;
- try
- {
- Jedis cache = new Jedis(APIBungee.getIP(), 3305, 0);
- cache.auth(APIBungee.getMDP());
- UUID = cache.hget("players:" + target_name + ":stats", "bungee_uuid");
- cache.close();
- }
- catch (Exception e2)
- {
- e2.printStackTrace();
- }
- if (UUID != null) {
- new SanctionManager(type, author, UUID, target_name, endtime, reason);
- } else {
- this.result = true;
- }
- }
- public SanctionManager(SanctionType type, String author, ProxiedPlayer target, String endtime, String reason)
- {
- this(type, author, target.getUniqueId().toString(), target.getName(), endtime, reason);
- }
- public SanctionManager(SanctionType type, String author, String target_uuid, String target_name, String endtime, String reason)
- {
- this.type = type;
- this.author = author;
- this.target_uuid = target_uuid;
- this.target_name = target_name;
- this.reason = reason;
- this.time = new Date();
- if (!endtime.contains(" "))
- {
- Integer minutes = Integer.valueOf(convertInMinutes(endtime));
- Date targetTime = new Date();
- this.endtime = DateUtils.addMinutes(targetTime, minutes.intValue());
- this.endtimeString = getTimeString(endtime, minutes.intValue());
- }
- else
- {
- SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
- try
- {
- this.endtime = sdf.parse(endtime);
- }
- catch (ParseException e)
- {
- e.printStackTrace();
- }
- }
- run();
- }
- public Date getEndtime()
- {
- return this.endtime;
- }
- public String getTarget_uuid()
- {
- return this.target_uuid;
- }
- public String getReason()
- {
- return this.reason;
- }
- private String getTimeString(String endtime, int min)
- {
- String time;
- String time;
- if (endtime.contains("min"))
- {
- time = min + " minute(s)";
- }
- else
- {
- String time;
- if (endtime.contains("h"))
- {
- time = min / 60 + " heure(s)";
- }
- else
- {
- String time;
- if (endtime.contains("j"))
- {
- time = min / 1440 + " jours";
- }
- else
- {
- String time;
- if (endtime.contains("s"))
- {
- time = min / 10080 + " semaine(s)";
- }
- else
- {
- String time;
- if (endtime.contains("mois")) {
- time = min / 43200 + " mois";
- } else {
- time = min / 518400 + " an(s)";
- }
- }
- }
- }
- }
- return time;
- }
- public void run()
- {
- String path = this.type.getPathredis();
- try
- {
- Jedis cache = new Jedis(APIBungee.getIP(), 3305, 0);
- cache.auth(APIBungee.getMDP());
- if (cache.exists(path).booleanValue())
- {
- SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
- String time = sdf.format(this.time);
- String endtime = sdf.format(this.endtime);
- String key = this.target_uuid.toString();
- String value = this.author + ";" + endtime + ";" + this.reason;
- cache.hset(path, key, value);
- if (this.target_name != null) {
- cache.hset("players:" + this.target_name + ":sanctions", time, this.type.getId() + "," + value);
- }
- }
- cache.close();
- this.result = false;
- }
- catch (Exception e2)
- {
- e2.printStackTrace();
- }
- }
- public void mutePlayer(ProxiedPlayer pp, boolean annonce)
- {
- if (this.endtimeString != null)
- {
- if (annonce) {
- ProxyServer.getInstance().broadcast(new ComponentBuilder("").append("§4§lGardenssProtect §f§l» §6" + pp.getName() + "§e est mute pendant §6" + this.endtimeString + ". §7§o(" + this.reason + ")").create());
- }
- pp.sendMessage(new ComponentBuilder("").create());
- pp.sendMessage(new ComponentBuilder("").append("§4§lGardenssProtect §f§l» §cVous avez été mute !").create());
- pp.sendMessage(new ComponentBuilder("").create());
- PlayerChatBungeeEvent.playersMute.add(this);
- }
- }
- public void disconnectPlayer(ProxiedPlayer pp)
- {
- if (this.endtimeString != null)
- {
- pp.disconnect(new ComponentBuilder("").append("§4§lGardenssProtect §f§l» §cVous avez été banni !").create());
- ProxyServer.getInstance().broadcast(new ComponentBuilder("").append("§4§lGardenssProtect §f§l» §6" + pp.getName() + "§e est banni pendant §6" + this.endtimeString + ". §7§o(" + this.reason + ")").create());
- }
- }
- public boolean failed()
- {
- return this.result;
- }
- private static int convertInMinutes(String args)
- {
- String patternMinutes = "[0-9]{1,3}min";
- String patternHours = "[0-9]{1,3}h";
- String patternDay = "[0-9]{1,3}j";
- String patternWeek = "[0-9]{1,3}s";
- String patternMonth = "[0-9]{1,3}mois";
- Pattern pMinutes = Pattern.compile(patternMinutes);
- Pattern pHours = Pattern.compile(patternHours);
- Pattern pDay = Pattern.compile(patternDay);
- Pattern pWeek = Pattern.compile(patternWeek);
- Pattern pMonth = Pattern.compile(patternMonth);
- Matcher mMinutes = pMinutes.matcher(args.toLowerCase());
- Matcher mHours = pHours.matcher(args.toLowerCase());
- Matcher mDay = pDay.matcher(args.toLowerCase());
- Matcher mWeek = pWeek.matcher(args.toLowerCase());
- Matcher mMonth = pMonth.matcher(args.toLowerCase());
- if (mMinutes.matches()) {
- return Integer.parseInt(args.split("min")[0]);
- }
- if (mHours.matches()) {
- return Integer.parseInt(Integer.valueOf(args.split("h")[0]).intValue() * 60 + "");
- }
- if (mDay.matches()) {
- return Integer.parseInt(Integer.valueOf(args.split("j")[0]).intValue() * 1440 + "");
- }
- if (mWeek.matches()) {
- return Integer.parseInt(Integer.valueOf(args.split("s")[0]).intValue() * 10080 + "");
- }
- if (mMonth.matches()) {
- return Integer.parseInt(Integer.valueOf(args.split("mois")[0]).intValue() * 43200 + "");
- }
- return Integer.parseInt("518400");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement