Skip to content

Commit

Permalink
Merge pull request #15 from iamnoksio/master
Browse files Browse the repository at this point in the history
Fix + Cleanup + Don't do useless action + Improvement
  • Loading branch information
sathonay authored Feb 1, 2023
2 parents 52f1ddc + 9a7436e commit 9b6223b
Show file tree
Hide file tree
Showing 40 changed files with 783 additions and 437 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build nPaper

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
cache: maven
- name: Build nPaper
run: mvn clean install
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: nPaper
path: ./nPaper-Server/target/npaper-1.7.10-R0.1-SNAPSHOT.jar
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ nbproject/
nbactions.xml

# we use maven!
build.xml
pom.xml

# maven
target/
Expand Down Expand Up @@ -37,4 +37,8 @@ manifest.mf

# other stuff
nPaper-Server/target
nPaper-Server/dependency-reduced-pom.xml
nPaper-API/target
nPaper-API/dependency-reduced-pom.xml
MinecraftServer/target
MinecraftServer/dependency-reduced-pom.xml
2 changes: 1 addition & 1 deletion MinecraftServer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
20 changes: 10 additions & 10 deletions nPaper-API/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>16.0.2</version>
<version>24.0.0</version>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
Expand All @@ -49,7 +49,7 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.12</version>
<version>1.33</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
Expand All @@ -70,7 +70,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>10.0.1</version>
<version>31.1-jre</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
Expand All @@ -83,7 +83,7 @@
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.8.5</version>
<version>2.9.3</version>
</dependency>


Expand All @@ -92,13 +92,13 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<version>2.2</version>
<scope>test</scope>
</dependency>
-->
Expand All @@ -109,7 +109,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -118,7 +118,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
Expand All @@ -131,7 +131,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.0-beta-3</version>
<version>4.0.0-M4</version>
<configuration>
<reportPlugins>
<plugin>
Expand All @@ -142,7 +142,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<version>3.4.1</version>
<configuration>
<linksource>true</linksource>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public boolean execute(CommandSender sender, String currentAlias, String[] args)
}

OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
if (!player.isOp()) {
sender.sendMessage("Player's not opped!");
return false;
}
player.setOp(false);

if (player instanceof Player) {
Expand All @@ -51,7 +55,7 @@ public List<String> tabComplete(CommandSender sender, String alias, String[] arg
List<String> completions = new ArrayList<String>();
for (OfflinePlayer player : Bukkit.getOperators()) {
String playerName = player.getName();
if (StringUtil.startsWithIgnoreCase(playerName, args[0])) {
if (StringUtil.startsWithIgnoreCase(playerName, args[0]) && player.isOp()) {
completions.add(playerName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ public List<String> tabComplete(CommandSender sender, String alias, String[] arg
return ImmutableList.of();
}

Player senderPlayer = (Player) sender;

ArrayList<String> matchedPlayers = new ArrayList<String>();
for (Player player : sender.getServer().getOnlinePlayers()) {
String name = player.getName();
if (!senderPlayer.canSee(player) || player.isOp()) {
if (player.isOp()) {
continue;
}
if (StringUtil.startsWithIgnoreCase(name, lastWord)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public boolean execute(CommandSender sender, String currentAlias, String[] args)
return false;
}

if (!Bukkit.getBanList(BanList.Type.NAME).isBanned(args[0])) {
sender.sendMessage("Player's not banned!");
return false;
}
Bukkit.getBanList(BanList.Type.NAME).pardon(args[0]);
Command.broadcastCommandMessage(sender, "Unbanned " + args[0]);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,13 @@ public List<String> tabComplete(CommandSender sender, String alias, String[] arg

if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], WHITELIST_SUBCOMMANDS, new ArrayList<String>(WHITELIST_SUBCOMMANDS.size()));
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("add")) {
List<String> completions = new ArrayList<String>();
}
if (args.length == 2) {
if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")) {
final List<String> completions = new ArrayList<String>();
for (OfflinePlayer player : Bukkit.getOnlinePlayers()) { // Spigot - well maybe sometimes you haven't turned the whitelist on just yet.
String name = player.getName();
if (StringUtil.startsWithIgnoreCase(name, args[1]) && !player.isWhitelisted()) {
completions.add(name);
}
}
return completions;
} else if (args[0].equalsIgnoreCase("remove")) {
List<String> completions = new ArrayList<String>();
for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) {
String name = player.getName();
if (StringUtil.startsWithIgnoreCase(name, args[1])) {
final String name = player.getName();
if (StringUtil.startsWithIgnoreCase(name, args[1]) && (args[0].equalsIgnoreCase("add") ? !player.isWhitelisted() : player.isWhitelisted())) {
completions.add(name);
}
}
Expand Down
25 changes: 25 additions & 0 deletions nPaper-API/src/main/java/org/bukkit/entity/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

import com.sathonay.npaper.Title;

import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;

/**
* Represents a player, connected or not
*/
Expand Down Expand Up @@ -901,6 +904,28 @@ public interface Player extends HumanEntity, Conversable, CommandSender, Offline
* Hide any title that is currently visible to the player
*/
public void hideTitle();

/**
* Sends an Action Bar message to the client.
*
* @param message message to display
*/
default void sendActionBar(String... message) {
BaseComponent[] messageComponents = new BaseComponent[message.length];
int i = 0;
for (String messageLine : message) {
messageComponents[i] = new TextComponent(messageLine);
i++;
}
sendActionBar(messageComponents);
}

/**
* Sends an Action Bar message to the client.
*
* @param message message to display
*/
void sendActionBar(BaseComponent... message);

/**
* Gets the Location where the player will spawn at their bed, null if
Expand Down
40 changes: 25 additions & 15 deletions nPaper-API/src/main/java/org/bukkit/metadata/MetadataStoreBase.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package org.bukkit.metadata;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.lang.Validate;
import org.bukkit.plugin.Plugin;

import java.util.*;

public abstract class MetadataStoreBase<T> {
private Map<String, Map<Plugin, MetadataValue>> metadataMap = new HashMap<String, Map<Plugin, MetadataValue>>();
private Map<String, Map<Plugin, MetadataValue>> metadataMap = new ConcurrentHashMap<String, Map<Plugin, MetadataValue>>();

/**
* Adds a metadata value to an object. Each metadata value is owned by a
Expand Down Expand Up @@ -40,7 +46,9 @@ public synchronized void setMetadata(T subject, String metadataKey, MetadataValu
entry = new WeakHashMap<Plugin, MetadataValue>(1);
metadataMap.put(key, entry);
}
entry.put(owningPlugin, newMetadataValue);
synchronized (entry) {
entry.put(owningPlugin, newMetadataValue);
}
}

/**
Expand All @@ -53,14 +61,14 @@ public synchronized void setMetadata(T subject, String metadataKey, MetadataValu
* requested value.
* @see MetadataStore#getMetadata(Object, String)
*/
public synchronized List<MetadataValue> getMetadata(T subject, String metadataKey) {
public List<MetadataValue> getMetadata(T subject, String metadataKey) {
String key = disambiguate(subject, metadataKey);
if (metadataMap.containsKey(key)) {
Collection<MetadataValue> values = metadataMap.get(key).values();
Map<Plugin, MetadataValue> entry = metadataMap.get(key);
if (entry != null) {
Collection<MetadataValue> values = entry.values();
return Collections.unmodifiableList(new ArrayList<MetadataValue>(values));
} else {
return Collections.emptyList();
}
return Collections.emptyList();
}

/**
Expand All @@ -71,7 +79,7 @@ public synchronized List<MetadataValue> getMetadata(T subject, String metadataKe
* @param metadataKey the unique metadata key being queried.
* @return the existence of the metadataKey within subject.
*/
public synchronized boolean hasMetadata(T subject, String metadataKey) {
public boolean hasMetadata(T subject, String metadataKey) {
String key = disambiguate(subject, metadataKey);
return metadataMap.containsKey(key);
}
Expand All @@ -87,17 +95,19 @@ public synchronized boolean hasMetadata(T subject, String metadataKey) {
* org.bukkit.plugin.Plugin)
* @throws IllegalArgumentException If plugin is null
*/
public synchronized void removeMetadata(T subject, String metadataKey, Plugin owningPlugin) {
public void removeMetadata(T subject, String metadataKey, Plugin owningPlugin) {
Validate.notNull(owningPlugin, "Plugin cannot be null");
String key = disambiguate(subject, metadataKey);
Map<Plugin, MetadataValue> entry = metadataMap.get(key);
if (entry == null) {
return;
}

entry.remove(owningPlugin);
if (entry.isEmpty()) {
metadataMap.remove(key);
synchronized (entry) {
entry.remove(owningPlugin);
if (entry.isEmpty()) {
metadataMap.remove(key);
}
}
}

Expand All @@ -110,7 +120,7 @@ public synchronized void removeMetadata(T subject, String metadataKey, Plugin ow
* @see MetadataStore#invalidateAll(org.bukkit.plugin.Plugin)
* @throws IllegalArgumentException If plugin is null
*/
public synchronized void invalidateAll(Plugin owningPlugin) {
public void invalidateAll(Plugin owningPlugin) {
Validate.notNull(owningPlugin, "Plugin cannot be null");
for (Map<Plugin, MetadataValue> values : metadataMap.values()) {
if (values.containsKey(owningPlugin)) {
Expand Down
Loading

0 comments on commit 9b6223b

Please sign in to comment.