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

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraLS3 authored Jul 23, 2017
1 parent f72aa8f commit 4b76453
Show file tree
Hide file tree
Showing 11 changed files with 385 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ private void sendDefaultCommand(ISender sender, String commandLabel, String[] ar
*/
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
plugin.getPluginLogger().debug("Registered command with arguments: " + Arrays.toString(args));
if (args.length < 1) {
sendDefaultCommand(sender, commandLabel, args);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SenderType;
import org.bukkit.ChatColor;
import org.bukkit.block.CommandBlock;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand All @@ -24,7 +25,24 @@ public BukkitCMDSender(CommandSender cs) {

@Override
public void sendMessage(String string) {
cs.sendMessage(string);
if (!(cs instanceof Player)) {
cs.sendMessage(string);
return;
}
final int length = string.length();
if (length > 100) {
int i = 99;
while (i < length && string.charAt(i) != ' ') {
i++;
}
String shortened = string.substring(0, i);
String lastCols = ChatColor.getLastColors(string);
cs.sendMessage(shortened);
String leftover = lastCols + string.substring(i);
sendMessage(leftover);
} else {
cs.sendMessage(string);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.djrapitops.plugin.command.bukkit;

import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.utilities.player.Fetch;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

/**
* Class that is used to wrap a SubCommand implementation into executable
Expand All @@ -23,6 +26,12 @@ public BukkitCommand(SubCommand subCmd) {

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
return subCmd.onCommand(new BukkitCMDSender(sender), label, args);
ISender iSender;
if (sender instanceof Player) {
iSender = Fetch.wrapBukkit((Player) sender);
} else {
iSender = new BukkitCMDSender(sender);
}
return subCmd.onCommand(iSender, label, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.djrapitops.plugin.utilities;

import java.util.Objects;

/**
*
* @author Rsl1122
* @since 2.0.0
*/
public class Format {

public static Format create(String string) {
return new Format(string);
}

private String string;

public Format(String string) {
this.string = string;
}

public Format removeLetters() {
string = FormattingUtils.removeLetters(string);
return this;
}

public Format removeSymbols() {
string = FormattingUtils.removeSymbols(string);
return this;
}
public Format removeSymbolsButDot() {
string = FormattingUtils.removeSymbolsButDot(string);
return this;
}
public Format removeDot() {
string = string.replaceAll("\\.", "");
return this;
}

public Format removeNumbers() {
string = FormattingUtils.removeNumbers(string);
return this;
}

public Format removeWhitespace() {
string = FormattingUtils.removeWhitespace(string);
return this;
}

public Format spaceWhatespace() {
string = FormattingUtils.spaceWhitespace(string);
return this;
}

public Format justNumbers() {
return this.removeLetters().removeSymbols().removeWhitespace();
}

public Format justLetters() {
return this.removeNumbers().removeSymbols().removeWhitespace();
}

public Format justSymbols() {
return this.removeNumbers().removeLetters().removeWhitespace();
}

public Format upperCase() {
string = string.toUpperCase();
return this;
}

public Format lowerCase() {
string = string.toLowerCase();
return this;
}

public Format capitalize() {
string = (string.charAt(0) + "").toUpperCase() + string.substring(1).toLowerCase();
return this;
}

@Override
public String toString() {
return string;
}

@Override
public int hashCode() {
int hash = 5;
hash = 67 * hash + Objects.hashCode(this.string);
return hash;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Format other = (Format) obj;
if (!Objects.equals(this.string, other.string)) {
return false;
}
return true;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static String formatTimeStampYear(long epochMs) {
* @return
*/
public static String removeLetters(String dataPoint) {
return dataPoint.replaceAll("[^\\d.]", "");
return dataPoint.replaceAll("[A-Za-z]", "");
}

/**
Expand All @@ -59,11 +59,22 @@ public static String removeLetters(String dataPoint) {
* @return
*/
public static String removeNumbers(String dataPoint) {
for (char c : removeLetters(dataPoint).toCharArray()) {
dataPoint = dataPoint.replace(c + "", "");
}
dataPoint = dataPoint.replace(" ", "");
return dataPoint;
return dataPoint.replaceAll("[0-9]", "");
}

public static String removeSymbols(String dataPoint) {
return dataPoint.replaceAll("[^a-zA-Z0-9_\\s]", "");
}
public static String removeSymbolsButDot(String dataPoint) {
return dataPoint.replaceAll("[^a-zA-Z0-9_\\s\\.]", "");
}

public static String spaceWhitespace(String dataPoint) {
return dataPoint.replaceAll("[\\s]", " ");
}

public static String removeWhitespace(String dataPoint) {
return dataPoint.replaceAll("[\\s]", "");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ public Optional<IPlayer> getPlayer(UUID uuid) throws NullPointerException, Illeg
} else {
throw new IllegalStateException("Can not get Player objecst without Bukkit or Bungee.");
}
return Optional.of(p);
if (p != null) {
return Optional.of(p);
} else {
return Optional.empty();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.djrapitops.plugin.utilities.player;

import com.djrapitops.plugin.IPlugin;
import com.djrapitops.plugin.command.ISender;
import java.net.InetSocketAddress;
import java.util.UUID;

/**
*
* @author Rsl1122
*/
public interface IPlayer extends IOfflinePlayer {
public interface IPlayer extends IOfflinePlayer, ISender {

public String getDisplayName();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.djrapitops.plugin.utilities.player.bukkit;

import com.djrapitops.plugin.BukkitPlugin;
import com.djrapitops.plugin.IPlugin;
import com.djrapitops.plugin.command.SenderType;
import com.djrapitops.plugin.utilities.player.Gamemode;
import com.djrapitops.plugin.utilities.player.IPlayer;
import java.net.InetSocketAddress;
Expand Down Expand Up @@ -148,4 +144,29 @@ public void sendPluginMessage(IPlugin plugin, String channel, byte[] bytes) {
plugin.getPluginLogger().toLog(this.getClass().getName(), e);
}
}

@Override
public void sendMessage(String string) {
p.sendMessage(string);
}

@Override
public void sendMessage(String[] strings) {
p.sendMessage(strings);
}

@Override
public boolean hasPermission(String string) {
return p.hasPermission(string);
}

@Override
public SenderType getSenderType() {
return SenderType.PLAYER;
}

@Override
public Object getSender() {
return getWrappedPlayerClass();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.djrapitops.plugin.utilities.player.bungee;

import com.djrapitops.plugin.IPlugin;
import com.djrapitops.plugin.command.SenderType;
import com.djrapitops.plugin.utilities.player.Gamemode;
import com.djrapitops.plugin.utilities.player.IPlayer;
import java.net.InetSocketAddress;
import java.util.UUID;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ConnectedPlayer;
import net.md_5.bungee.api.connection.ProxiedPlayer;

/**
*
Expand Down Expand Up @@ -131,4 +134,32 @@ public UUID getUuid() {
public long getRegistered() {
return getFirstPlayed();
}

@Override
public void sendMessage(String string) {
ComponentBuilder c = new ComponentBuilder(string);
p.sendMessage(c.create());
}

@Override
public boolean hasPermission(String string) {
return p.hasPermission(string);
}

@Override
public void sendMessage(String[] strings) {
for (int i = 1; i < strings.length; i++) {
sendMessage(strings[i]);
}
}

@Override
public SenderType getSenderType() {
return p instanceof ConnectedPlayer ? SenderType.PLAYER : (p instanceof ProxiedPlayer ? SenderType.PROXY_PLAYER : SenderType.CONSOLE);
}

@Override
public Object getSender() {
return getWrappedPlayerClass();
}
}
Loading

0 comments on commit 4b76453

Please sign in to comment.