Skip to content

Commit

Permalink
v1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRazamataz committed Jan 9, 2022
1 parent d567714 commit 891ee2c
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 96 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>raza</groupId>
<artifactId>stanban</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
274 changes: 181 additions & 93 deletions src/main/java/raza/$stanban/PluginMain.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,79 @@
package raza.$stanban;

import java.io.*;
import java.nio.file.*;
import java.util.*;

import org.bukkit.*;
import org.bukkit.command.*;
import org.bukkit.event.*;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.*;

public class PluginMain extends JavaPlugin implements Listener {

private static PluginMain instance;
private static PluginMain instance;

@Override
public void onEnable() {
instance = this;
getDataFolder().mkdir();
getServer().getPluginManager().registerEvents(this, this);
saveDefaultConfig();
try {
PluginMain.getInstance().getLogger()
.info(ChatColor.translateAlternateColorCodes('&', "[&cStanBan&r] &6Running version: 1.1.1"));
PluginMain.getInstance().getLogger()
.info(ChatColor.translateAlternateColorCodes('&', "[&cStanBan&r] Loading config..."));
PluginMain.getInstance().getLogger()
.info(ChatColor.translateAlternateColorCodes('&', "[&cStanBan&r] Config loaded!"));
PluginMain.getInstance().getLogger().info(ChatColor.translateAlternateColorCodes('&',
"[&cStanBan&r] &aPlugin has been enabled and is active. Ready!"));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onEnable() {
instance = this;
getDataFolder().mkdir();
getServer().getPluginManager().registerEvents(this, this);
PluginMain.createResourceFile("banned.txt");
saveDefaultConfig();
try {
if (PluginMain.hasUpdate("98924", true)) {
PluginMain.getInstance().getLogger()
.warning((ChatColor.translateAlternateColorCodes('&',
"[&cStanBan&r] &6There is an update available which is: ")
+ PluginMain.getNewVersion("98924", true)));
}
PluginMain.getInstance().getLogger()
.info((ChatColor.translateAlternateColorCodes('&', "[&cStanBan&r] &6Running version: ")
+ PluginMain.getInstance().getDescription().getVersion()));
new Metrics(PluginMain.getInstance(), ((int) (13846d)));
PluginMain.getInstance().getLogger()
.info(ChatColor.translateAlternateColorCodes('&', "[&cStanBan&r] Loading config..."));
PluginMain.getInstance().getLogger()
.info(ChatColor.translateAlternateColorCodes('&', "[&cStanBan&r] Config loaded!"));
PluginMain.getInstance().getLogger().info(ChatColor.translateAlternateColorCodes('&',
"[&cStanBan&r] &aPlugin has been enabled and is active. Ready!"));
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void onDisable() {
try {
PluginMain.getInstance().getLogger()
.info(ChatColor.translateAlternateColorCodes('&', "[&cStanBan&r] &cPlugin has been disabled."));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onDisable() {
try {
PluginMain.getInstance().getLogger()
.info(ChatColor.translateAlternateColorCodes('&', "[&cStanBan&r] &cPlugin has been disabled."));
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public boolean onCommand(CommandSender commandSender, Command command, String label, String[] commandArgs) {
if (command.getName().equalsIgnoreCase("unbanallstans")) {
try {
commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aUnbanning all stans..."));
for (Object FINAL_loopValue1 : java.nio.file.Files.readAllLines(
new File(String.valueOf(PluginMain.getInstance().getDataFolder()), "banned.txt").toPath(),
java.nio.charset.StandardCharsets.UTF_8)) {
((org.bukkit.BanList) org.bukkit.Bukkit
.getBanList(((org.bukkit.BanList.Type) org.bukkit.BanList.Type.NAME)))
.pardon(String.valueOf(FINAL_loopValue1));
commandSender.sendMessage((ChatColor.translateAlternateColorCodes('&',
ChatColor.translateAlternateColorCodes('&', "&aUnbanned: &c"))
+ String.valueOf(FINAL_loopValue1)));
}
new File(String.valueOf(PluginMain.getInstance().getDataFolder()), "banned.txt").delete();
new File(String.valueOf(PluginMain.getInstance().getDataFolder()), "banned.txt").createNewFile();
commandSender
.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aAll stans have been unbanned!"));
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
if (command.getName().equalsIgnoreCase("stanbanreload")) {
try {
PluginMain.getInstance().reloadConfig();
Expand All @@ -67,68 +95,128 @@ public boolean onCommand(CommandSender commandSender, Command command, String la
return true;
}

public static List createList(Object obj) {
if (obj instanceof List) {
return (List) obj;
}
List list = new ArrayList<>();
if (obj.getClass().isArray()) {
int length = java.lang.reflect.Array.getLength(obj);
for (int i = 0; i < length; i++) {
list.add(java.lang.reflect.Array.get(obj, i));
}
} else if (obj instanceof Collection<?>) {
list.addAll((Collection<?>) obj);
} else if (obj instanceof Iterator) {
((Iterator<?>) obj).forEachRemaining(list::add);
} else {
list.add(obj);
}
return list;
}
public static void procedure(String procedure, List procedureArgs) throws Exception {
}

public static void createResourceFile(String path) {
Path file = getInstance().getDataFolder().toPath().resolve(path);
if (Files.notExists(file)) {
try (InputStream inputStream = PluginMain.class.getResourceAsStream("/" + path)) {
Files.createDirectories(file.getParent());
Files.copy(inputStream, file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static Object function(String function, List functionArgs) throws Exception {
return null;
}

public static PluginMain getInstance() {
return instance;
}
public static List createList(Object obj) {
if (obj instanceof List) {
return (List) obj;
}
List list = new ArrayList<>();
if (obj.getClass().isArray()) {
int length = java.lang.reflect.Array.getLength(obj);
for (int i = 0; i < length; i++) {
list.add(java.lang.reflect.Array.get(obj, i));
}
} else if (obj instanceof Collection<?>) {
list.addAll((Collection<?>) obj);
} else if (obj instanceof Iterator) {
((Iterator<?>) obj).forEachRemaining(list::add);
} else {
list.add(obj);
}
return list;
}

public static void createResourceFile(String path) {
Path file = getInstance().getDataFolder().toPath().resolve(path);
if (Files.notExists(file)) {
try (InputStream inputStream = PluginMain.class.getResourceAsStream("/" + path)) {
Files.createDirectories(file.getParent());
Files.copy(inputStream, file);
} catch (IOException e) {
e.printStackTrace();
}
}
}

@EventHandler(priority = EventPriority.HIGHEST)
public void event1(PlayerJoinEvent event) throws Exception {
Object $24c5b3a5b3df7260f1023d2b3f1dcdcc = null;
$24c5b3a5b3df7260f1023d2b3f1dcdcc = true;
for (Object FINAL_loopValue1 : ((java.util.List) PluginMain.getInstance().getConfig().get("stanban.names"))) {
if (String.valueOf(event.getPlayer()).contains(String.valueOf(FINAL_loopValue1))) {
Bukkit.getBanList(BanList.Type.NAME).addBan(((CommandSender) event.getPlayer()).getName(), ChatColor.translateAlternateColorCodes('&', String
.valueOf(PluginMain.getInstance().getConfig().get("stanban.ban-message"))
.replaceAll("%player%",
event.getPlayer().getDisplayName())), null, ChatColor.translateAlternateColorCodes('&', "[&cStanBan&r]"));
event.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', String
.valueOf(PluginMain.getInstance().getConfig().get("stanban.ban-message")).replaceAll("%player%", event.getPlayer().getDisplayName())));
if (((boolean) $24c5b3a5b3df7260f1023d2b3f1dcdcc)) {
org.bukkit.Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', String
.valueOf(PluginMain.getInstance().getConfig().get("stanban.chat-broadcast-message"))
.replaceAll("%player%", event.getPlayer().getDisplayName())));
$24c5b3a5b3df7260f1023d2b3f1dcdcc = false;
if (((boolean) PluginMain.getInstance().getConfig().get("actions.enabled"))) {
for (Object FINAL_loopValue2 : ((java.util.List) PluginMain.getInstance().getConfig()
.get("actions.on-stan-join-commands"))) {
org.bukkit.Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
String.valueOf(FINAL_loopValue2).replaceAll("%player%", event.getPlayer().getDisplayName()));
}
}
}
}
}
}
public static PluginMain getInstance() {
return instance;
}

@EventHandler(priority = EventPriority.HIGHEST)
public void event1(org.bukkit.event.player.PlayerJoinEvent event) throws Exception {
Object $24c5b3a5b3df7260f1023d2b3f1dcdcc = null;
$24c5b3a5b3df7260f1023d2b3f1dcdcc = ((java.lang.Object) (Object) true);
for (Object FINAL_loopValue1 : ((java.util.List) (Object) PluginMain.getInstance().getConfig()
.get("stanban.names"))) {
if (((boolean) String.valueOf(((org.bukkit.entity.Player) event.getPlayer()))
.contains(String.valueOf(FINAL_loopValue1)))) {
((org.bukkit.BanList) org.bukkit.Bukkit
.getBanList(((org.bukkit.BanList.Type) org.bukkit.BanList.Type.NAME))).addBan(
((java.lang.String) ((org.bukkit.command.CommandSender) (Object) ((org.bukkit.entity.Player) event
.getPlayer())).getName()),
ChatColor.translateAlternateColorCodes('&', ((java.lang.String) String
.valueOf(PluginMain.getInstance().getConfig().get("stanban.ban-message"))
.replaceAll("%player%",
((java.lang.String) ((org.bukkit.entity.Player) event.getPlayer())
.getDisplayName())))),
((java.util.Date) null), ChatColor.translateAlternateColorCodes('&', "[&cStanBan&r]"));
((org.bukkit.entity.Player) event.getPlayer()).kickPlayer(ChatColor.translateAlternateColorCodes('&',
((java.lang.String) String
.valueOf(PluginMain.getInstance().getConfig().get("stanban.ban-message")).replaceAll(
"%player%", ((java.lang.String) ((org.bukkit.entity.Player) event.getPlayer())
.getDisplayName())))));
if (((boolean) (Object) $24c5b3a5b3df7260f1023d2b3f1dcdcc)) {
org.bukkit.Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',
((java.lang.String) String
.valueOf(PluginMain.getInstance().getConfig().get("stanban.chat-broadcast-message"))
.replaceAll("%player%",
((java.lang.String) ((org.bukkit.entity.Player) event.getPlayer())
.getDisplayName())))));
$24c5b3a5b3df7260f1023d2b3f1dcdcc = ((java.lang.Object) (Object) false);
if (((boolean) (Object) PluginMain.getInstance().getConfig().get("actions.enabled"))) {
for (Object FINAL_loopValue2 : ((java.util.List) (Object) PluginMain.getInstance().getConfig()
.get("actions.on-stan-join-commands"))) {
org.bukkit.Bukkit.dispatchCommand(
((org.bukkit.command.CommandSender) (Object) ((org.bukkit.command.ConsoleCommandSender) org.bukkit.Bukkit
.getConsoleSender())),
((java.lang.String) String.valueOf(FINAL_loopValue2).replaceAll("%player%",
((java.lang.String) ((org.bukkit.entity.Player) event.getPlayer())
.getDisplayName()))));
}
}
java.nio.file.Files.write(
new File(String.valueOf(PluginMain.getInstance().getDataFolder()), "banned.txt").toPath(),
Collections.singleton(((java.lang.String) ((org.bukkit.entity.Player) event.getPlayer())
.getDisplayName())),
java.nio.charset.StandardCharsets.UTF_8, java.nio.file.StandardOpenOption.APPEND);
}
}
}
}

public static boolean hasUpdate(String resourceId, boolean throwInError) {
boolean hasUpdate = false;
try (java.io.InputStream inputStream = new java.net.URL(
"https://api.spigotmc.org/legacy/update.php?resource=" + resourceId).openStream();
java.util.Scanner scanner = new java.util.Scanner(inputStream)) {
if (scanner.hasNext())
hasUpdate = !PluginMain.getInstance().getDescription().getVersion().equalsIgnoreCase(scanner.next());
} catch (java.io.IOException ioException) {
hasUpdate = false;
if (throwInError)
ioException.printStackTrace();
}
return hasUpdate;
}

public static String getNewVersion(String resourceId, boolean throwInError) {
String newVersion = PluginMain.getInstance().getDescription().getVersion();
try (java.io.InputStream inputStream = new java.net.URL(
"https://api.spigotmc.org/legacy/update.php?resource=" + resourceId).openStream();
java.util.Scanner scanner = new java.util.Scanner(inputStream)) {
if (scanner.hasNext())
newVersion = String.valueOf(scanner.next());
} catch (java.io.IOException ioException) {
newVersion = "Sal4iDev#4767";
if (throwInError)
ioException.printStackTrace();
}
return newVersion;
}
}
Empty file added src/main/resources/banned.txt
Empty file.
8 changes: 6 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "StanBan"
version: "1.1.2"
version: "1.1.3"
main: "raza.$stanban.PluginMain"
api-version: 1.13
author: "MrRazamataz"
Expand All @@ -10,5 +10,9 @@ commands:
aliases: [sbreload]
description: "Reloads StanBan's config file"
permission: "stanban.reload"
permission-message: "[§cStanBan§r] §cYou do not have permisson for that command!"
permission-message: "[§cStanBan§r] §cYou do not have permisson for that command! You need the permisson stanban.reload"
unbanallstans:
description: "Unban all of the players that StanBan has banned!"
permission: "stanban.unbanall"
permission-message: "[§cStanBan§r] §cYou do not have permisson for that command! You need the permisson stanban.unbanall"
permissions:

0 comments on commit 891ee2c

Please sign in to comment.