Skip to content

Commit

Permalink
Merge pull request #1 from SFTMedia/update-removedep-stringutils
Browse files Browse the repository at this point in the history
Update removedep stringutils
  • Loading branch information
SFTMedia authored Feb 16, 2020
2 parents 9ce33b7 + d20493d commit 243d9c4
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 42 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
libs/
target/
target/
.project
.settings
.classpath
.vscode
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# CustomPrefix
Allows users to request custom prefixes, and prompts staff to confirm

# Versions
Should work on 1.7+
19 changes: 15 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.blalp</groupId>
<artifactId>customprefix</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<packaging>jar</packaging>

<name>CustomPrefix</name>
Expand Down Expand Up @@ -34,12 +34,23 @@
<id>other-plugins</id>
<url>file://${project.basedir}/libs/other-plugins</url>
</repository>
<repository>
<id>spigot</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org</groupId>
<artifactId>bukkit</artifactId>
<version>1.7.10</version>
<groupId>ru</groupId>
<artifactId>tehkode</artifactId>
<version>1.23.4</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.15.1-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
Expand All @@ -30,7 +29,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if(getConfig().getInt("players.time."+((Player)sender).getUniqueId())+getConfig().getInt("delayDays")<=getCustomDate()){
//PrefixRequest prefixRequest = new PrefixRequest();
//prefixRequest.setPlayername(sender.getName());
//prefixRequest.setRequestedPrefix(StringUtils.join(args," "));
//prefixRequest.setRequestedPrefix(join(args));
List<String> players = (List<String>) getConfig().getList("playerList");
if(players==null){
players = new ArrayList<String>();
Expand All @@ -39,11 +38,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
players.add(((Player)sender).getUniqueId().toString());
getConfig().set("playerList", players);
}
getConfig().set("players."+((Player)sender).getUniqueId()+".requestedPrefix", StringUtils.join(args," "));
getConfig().set("players."+((Player)sender).getUniqueId()+".requestedPrefix", join(args));
getConfig().set("players."+((Player)sender).getUniqueId()+".status", "pending");
saveConfig();
sender.sendMessage(ChatColor.WHITE+"["+ChatColor.BLUE+"CustomPrefix"+ChatColor.WHITE+"] "+"You requested the prefix '"+handleColors(StringUtils.join(args," "))+ChatColor.WHITE+"' Please hold on while our staff screen this prefix.");
Bukkit.broadcast(ChatColor.WHITE+"["+ChatColor.BLUE+"CustomPrefix"+ChatColor.WHITE+"] "+sender.getName()+" requested "+handleColors(StringUtils.join(args," "))+sender.getName()+ChatColor.WHITE+". do /prefixpending [accept/reject] "+sender.getName()+" [reason]", "customprefix.admin");
sender.sendMessage(ChatColor.WHITE+"["+ChatColor.BLUE+"CustomPrefix"+ChatColor.WHITE+"] "+"You requested the prefix '"+handleColors(join(args))+ChatColor.WHITE+"' Please hold on while our staff screen this prefix.");
Bukkit.broadcast(ChatColor.WHITE+"["+ChatColor.BLUE+"CustomPrefix"+ChatColor.WHITE+"] "+sender.getName()+" requested "+handleColors(join(args))+sender.getName()+ChatColor.WHITE+". do /prefixpending [accept/reject] "+sender.getName()+" [reason]", "customprefix.admin");
} else {
sender.sendMessage(ChatColor.WHITE+"["+ChatColor.BLUE+"CustomPrefix"+ChatColor.WHITE+"] "+"Please wait "+(getConfig().getInt("players.time."+((Player)sender).getUniqueId())+getConfig().getInt("delayDays")-getCustomDate())+" days before you can request another prefix.");
}
Expand All @@ -53,6 +52,10 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return true;
} else if (cmd.getName().equalsIgnoreCase("prefixpending")){//usage: /<command> <accept/reject/get> <playername> <reason>
if(sender.hasPermission("customprefix.admin")){
if(args.length==0){
sender.sendMessage(ChatColor.WHITE+"["+ChatColor.BLUE+"CustomPrefix"+ChatColor.WHITE+"]"+" usage: /"+cmd.getName()+" (get|list|accept|reject)");
return false;
}
if(args.length<2&&!(args[0].equalsIgnoreCase("get")||args[0].equalsIgnoreCase("list"))){
sender.sendMessage(ChatColor.WHITE+"["+ChatColor.BLUE+"CustomPrefix"+ChatColor.WHITE+"] "+"Error, please follow this format. /prefixpending get or /prefixpending <accept/reject> <playername> <reason>");
return true;
Expand All @@ -66,6 +69,10 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}
}
} else if (args[0].equalsIgnoreCase("accept")||args[0].equalsIgnoreCase("yes")||args[0].equalsIgnoreCase("approve")){
if(args.length<2){
sender.sendMessage(ChatColor.WHITE+"["+ChatColor.BLUE+"CustomPrefix"+ChatColor.WHITE+"] "+"Usage: /"+cmd.getName()+" accept [name] [reason]");
return false;
}
Boolean found = false;
if(players!=null){
for(int i=0;i<players.size();i++){
Expand All @@ -77,9 +84,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
for(int ii=2;ii<args.length;ii++){
newArgs[ii-2]=args[ii];
}
getConfig().set("players."+players.get(i)+".reason", StringUtils.join(newArgs, " "));
getConfig().set("players."+players.get(i)+".reason", join(newArgs));
getConfig().set("players."+players.get(i)+".status", "accepted");
//prefixRequest.setDeniedReason(StringUtils.join(newArgs, " "));
//prefixRequest.setDeniedReason(join(newArgs));
//prefixRequest.setRequestedPrefix(pending.get(i).getReqskyuestedPrefix());
//pending.remove(i);
//getConfig().set("pending", pending);
Expand All @@ -89,7 +96,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
sender.sendMessage(ChatColor.WHITE+"["+ChatColor.BLUE+"CustomPrefix"+ChatColor.WHITE+"] You accepted "+args[1]+"'s Request ("+handleColors(getConfig().getString("players."+players.get(i)+".requestedPrefix"))+ChatColor.WHITE+")"+((getConfig().getString("players."+players.get(i)+".reason").equals(""))?"":" because "+getConfig().getString("players."+players.get(i)+".reason")+"!"));
if(Bukkit.getPlayer(args[1])!=null){
PermissionsEx.getUser(Bukkit.getPlayer(args[1])).setPrefix(getConfig().getString("players."+players.get(i)+".requestedPrefix"), "*");;
Bukkit.getPlayer(args[1]).sendMessage(ChatColor.WHITE+"["+ChatColor.BLUE+"CustomPrefix"+ChatColor.WHITE+"]"+" Your prefix was accepted! Thank you for donating! "+((StringUtils.join(newArgs, " ").equals(""))? "":("Your prefix was accepted"+((StringUtils.join(newArgs," ").equals(""))?"":" becauase: '"+StringUtils.join(newArgs, " ")+"'"+"!"))));
Bukkit.getPlayer(args[1]).sendMessage(ChatColor.WHITE+"["+ChatColor.BLUE+"CustomPrefix"+ChatColor.WHITE+"]"+" Your prefix was accepted! Thank you for donating! "+((join(newArgs).equals(""))? "":("Your prefix was accepted"+((join(newArgs).equals(""))?"":" becauase: '"+join(newArgs)+"'"+"!"))));
int count = getConfig().getInt("players."+players.get(i)+".prefixrequests");
getConfig().set("players."+players.get(i), "");
if(count!=1){
Expand All @@ -112,6 +119,10 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
sender.sendMessage(ChatColor.WHITE+"["+ChatColor.BLUE+"CustomPrefix"+ChatColor.WHITE+"] "+"No pending requests.");
}
} else if (args[0].equalsIgnoreCase("reject")||args[0].equalsIgnoreCase("no")||args[0].equalsIgnoreCase("deny")){
if(args.length<2){
sender.sendMessage(ChatColor.WHITE+"["+ChatColor.BLUE+"CustomPrefix"+ChatColor.WHITE+"] "+"Usage: /"+cmd.getName()+" reject [name] [reason]");
return false;
}
Boolean found = false;
if(players!=null){
for(int i=0;i<players.size();i++){
Expand All @@ -123,7 +134,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
for(int ii=2;ii<args.length;ii++){
newArgs[ii-2]=args[ii];
}
getConfig().set("players."+players.get(i)+".reason", StringUtils.join(newArgs, " "));
getConfig().set("players."+players.get(i)+".reason", join(newArgs));
getConfig().set("players."+players.get(i)+".status", "denied");
//prefixRequest.setDeniedReason(StringUtils.join(newArgs," "));
//prefixRequest.setRequestedPrefix(pending.get(i).getRequestedPrefix());
Expand Down Expand Up @@ -163,6 +174,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}
}
} else if (cmd.getName().equalsIgnoreCase("prefixadmin")){
if(args.length!=1){
sender.sendMessage(ChatColor.WHITE+"["+ChatColor.BLUE+"CustomPrefix"+ChatColor.WHITE+"]"+" usage: /"+cmd.getName()+" PLAYER_NAME");
sender.sendMessage("This will give them the ability to request a prefix.");
return false;
}
if(sender.hasPermission("customprefix.console")){
if(getConfig().contains("players."+Bukkit.getOfflinePlayer(args[0]).getUniqueId()+".prefixrequests")){
getConfig().set("players."+Bukkit.getOfflinePlayer(args[0]).getUniqueId()+".prefixrequests", getConfig().getInt("players."+Bukkit.getOfflinePlayer(args[0]).getUniqueId()+".prefixrequests")+1);
Expand All @@ -185,11 +201,19 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}
private String handleColors(String input){
if(input!=null){
return input.replaceAll("&","§");
return input.replaceAll("&","§");
} else {
return null;
}
}
private static String join(Object[] in){
String output="";
for(Object item: in){
output+=item.toString()+" ";
}
output=output.substring(0,output.length()-2);
return output;
}
@SuppressWarnings("deprecation")
public static int getCustomDate(){
Date date = new Date();
Expand All @@ -199,30 +223,3 @@ public static CustomPrefix getInstance() {
return instance;
}
}
/*
* package com.blalp.custompref;
public class PrefixRequest {
private String playername = "";
private String requestedPrefix ="";
private String reason = "";
public String getReason() {
return reason;
}
public String getPlayername() {
return playername;
}
public String getRequestedPrefix() {
return requestedPrefix;
}
public void setDeniedReason(String deniedReason) {
this.reason = deniedReason;
}
public void setPlayername(String playername) {
this.playername = playername;
}
public void setRequestedPrefix(String requestedPrefix) {
this.requestedPrefix = requestedPrefix;
}
}
*/
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions plugin.yml → src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: CustomPrefix
main: com.blalp.custompref.CustomPrefix
version: 1.0
depend: [PermissionsEx]

commands:
prefix:
Expand Down

0 comments on commit 243d9c4

Please sign in to comment.